Skip to contentSkip to conversation

sysfs.h: add ATTRIBUTE_GROUPS() macro

PATCH Guenter Roeck 2 participants 3 messages Jul 10, 2013

lore
Share & tools
lore
#0 lore raw
Quoted 14 lines · Greg Kroah-Hartman

To make it easier for driver subsystems to work with attribute groups, create the ATTRIBUTE_GROUPS macro to remove some of the repetitive typing for the most common use for attribute groups.

---
 include/linux/sysfs.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/sysfs.h +0 -0
index 9cd20c8..f62ff01 100644

include/linux/sysfs.h struct attribute_group { · line 97

Quoted 4 lines
include/linux/sysfs.h +1 -0
@@ -94,6 +94,15 @@ struct attribute_group {
 #define __ATTR_IGNORE_LOCKDEP	__ATTR
 #endif
 
+#define ATTRIBUTE_GROUPS(name)					\

Would it be possible to add is_visible as additional argument ?

Thanks,
Guenter

Quoted 15 lines
include/linux/sysfs.h +8 -0
+static const struct attribute_group name##_group = {		\
+	.attrs = name##_attrs,					\
+};								\
+static const struct attribute_group *name##_groups[] = {	\
+	&name##_group,						\
+	NULL,							\
+}
+
 #define attr_name(_attr) (_attr).attr.name
 
 struct file;
Signature · 1 line
1.8.3.rc0.20.gb99dd2e
#1 lore raw
Quoted 18 lines · Guenter Roeck
Quoted 17 lines · Greg Kroah-Hartman

To make it easier for driver subsystems to work with attribute groups, create the ATTRIBUTE_GROUPS macro to remove some of the repetitive typing for the most common use for attribute groups.

---
 include/linux/sysfs.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/sysfs.h +0 -0
index 9cd20c8..f62ff01 100644
@@ -94,6 +94,15 @@ struct attribute_group {
 #define __ATTR_IGNORE_LOCKDEP	__ATTR
 #endif
 
Quoted 3 lines

include/linux/sysfs.h struct attribute_group { · line 97

Quoted 1 line
include/linux/sysfs.h +1 -0
+#define ATTRIBUTE_GROUPS(name)					\

Would it be possible to add is_visible as additional argument ?

I thought about the other options (multiple groups, is_visible, and bin_attrs), but those are almost all not the "normal" usage, so I figure it's worth the extra 6 lines of text if you want to support is_visible or binary attributes.

After converting all of the class code to use groups, it seems to match up with the defaults, but if in the future it's more popular than expected, I'll gladly add it.

thanks,

greg k-h

#2 lore raw
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Guenter Roeck
Quoted 17 lines · Greg Kroah-Hartman

To make it easier for driver subsystems to work with attribute groups, create the ATTRIBUTE_GROUPS macro to remove some of the repetitive typing for the most common use for attribute groups.

---
 include/linux/sysfs.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/sysfs.h +0 -0
index 9cd20c8..f62ff01 100644
@@ -94,6 +94,15 @@ struct attribute_group {
 #define __ATTR_IGNORE_LOCKDEP	__ATTR
 #endif
 
Quoted 9 lines
Quoted 3 lines

include/linux/sysfs.h struct attribute_group { · line 97

Quoted 1 line
include/linux/sysfs.h +1 -0
+#define ATTRIBUTE_GROUPS(name)					\

Would it be possible to add is_visible as additional argument ?

I thought about the other options (multiple groups, is_visible, and bin_attrs), but those are almost all not the "normal" usage, so I figure it's worth the extra 6 lines of text if you want to support is_visible or binary attributes.

Ok, fair enough.

Thanks,
Guenter