David E. Box wrote: > Introduce macros to reduce boilerplate in attribute group definitions. > Combine DEFINE_SYSFS_ATTRIBUTE_GROUP_[COMBO]_VISIBILITY() with attribute > definitions in order to simplify group declarations involving visibility > logic. > > Signed-off-by: David E. Box <david.e.box@xxxxxxxxxxxxxxx> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> > --- > include/linux/sysfs.h | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h > index 00dc88776f21..0804bffd6013 100644 > --- a/include/linux/sysfs.h > +++ b/include/linux/sysfs.h > @@ -303,6 +303,30 @@ static const struct attribute_group _name##_group = { \ > }; \ > __ATTRIBUTE_GROUPS(_name) > > +#define NAMED_ATTRIBUTE_GROUP_VISIBLE(_name) \ > +DEFINE_SYSFS_GROUP_VISIBILITY(_name); \ > +static const struct attribute_group _name##_group = { \ > + .name = __stringify(_name), \ > + .attrs = _name##_attrs, \ > + .is_visible = SYSFS_GROUP_VISIBLE(_name), \ > +} > + > +#define NAMED_ATTRIBUTE_GROUPS_VISIBLE(_name) \ > +NAMED_ATTRIBUTE_GROUP_VISIBLE(_name); \ > +__ATTRIBUTE_GROUPS(_name) > + > +#define NAMED_ATTRIBUTE_GROUP_COMBO_VISIBLE(_name) \ > +DEFINE_SYSFS_GROUP_COMBO_VISIBILITY(_name); \ > +static const struct attribute_group _name##_group = { \ > + .name = __stringify(_name), \ > + .attrs = _name##_attrs, \ > + .is_visible = SYSFS_GROUP_VISIBLE(_name), \ > +} > + > +#define NAMED_ATTRIBUTE_GROUPS_COMBO_VISIBLE(_name) \ > +NAMED_ATTRIBUTE_GROUP_COMBO_VISIBLE(_name); \ > +__ATTRIBUTE_GROUPS(_name) > + Looks good to me, I like that this makes clear that it is setting { .name } in the resulting group. I would not mind a comment like "See DEFINE_SYSFS_GROUP_COMBO_VISIBILITY for method definition requirements", but only add that as a follow-on patch if someone else acks that idea. Reviewed-by: Dan Williams <dan.j.williams@xxxxxxxxx>