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) + struct file; struct vm_area_struct; struct address_space; -- 2.43.0