Skip to content

sysfs: Introduce macros for attribute groups with visibility control

David E. Box linux-doc linux-pci linux-sound lkml llvm oe-kbuild-all platform-driver-x86 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 11 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7sysfs: Rename attribute group visibility macrosinclude/linux/sysfs.h+17 -111 reply
2/7sysfs: Introduce macros to simplify creation of visible attribute groupsinclude/linux/sysfs.h+24 -01 reply
3/7docs: sysfs.rst: document additional attribute group macrosDocumentation/filesystems/sysfs.rst+244 -01 reply
4/7pci: doe: Replace sysfs visibility macrodrivers/pci/doe.c+1 -14 replies
5/7soundwire: sysfs: Use ATTRIBUTE_GROUP_VISIBLE()drivers/soundwire/sysfs_slave.c+13 -191 reply
6/7platform/x86/dell: alienware-wmi: update sysfs visibility macrosdrivers/platform/x86/dell/alienware-wmi-base.c drivers/platform/x86/dell/alienware-wmi-wmax.c+13 -172 replies
7/7sysfs: Remove transitional attribute group alias macrosinclude/linux/sysfs.h+0 -61 reply

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchAndy ShevchenkoKurt BorjaDan Williams
1/7R-b
2/7R-b R-b
3/7R-b
4/7R-b
5/7R-b R-b
6/7R-b R-b
7/7R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH 0/7] sysfs: Introduce macros for attribute groups with visibility control

The ATTRIBUTE_GROUP() helper does not support adding an .is_visible function for visibility control. With the introduction of SYSFS_GROUP_VISIBLE, DEFINE_SYSFS_GROUP_VISIBLE, and related macros, attribute group definitions can now fully encapsulate visibility logic while eliminating boilerplate code.

The following new macros are introduced:

NAMED_ATTRIBUTE_GROUP_VISIBLE()
NAMED_ATTRIBUTE_GROUPS_VISIBLE()
NAMED_ATTRIBUTE_GROUP_COMBO_VISIBLE()
NAMED_ATTRIBUTE_GROUPS_COMBO_VISIBLE()

This isn’t just a cleanup effort — I plan to use these macros in new driver code I'm working on, and wanted to avoid having to open-code these common visibility patterns yet again. Documenting and generalizing them now will help avoid duplication and make future code easier to read and maintain.

These macros integrate visibility logic directly into attribute group definitions, improving readability and maintainability. The DEFINE[_SIMPLE_]ATTRIBUTE_GROUP_VISIBLE() macros current have four users. Two out of them could be modified. The usbtouchscreen driver uses the @name field which isn't supported by ATTRIBUTE_GROUPS(). But for the ones that could be modified the diffstat was significant:

 drivers/pci/doe.c                              |  2 +-
 drivers/platform/x86/dell/alienware-wmi-base.c | 23 +++++++++--------------
 drivers/platform/x86/dell/alienware-wmi-wmax.c |  7 ++++---
 drivers/soundwire/sysfs_slave.c                | 32 +++++++++++++-------------------
 4 files changed, 27 insertions(+), 37 deletions(-)

David E. Box (7):
sysfs: Rename attribute group visibility macros
sysfs: Introduce macros to simplify creation of visible attribute
groups
docs: sysfs.rst: document additional attribute group macros
pci: doe: Replace sysfs visibility macro
soundwire: sysfs: Use ATTRIBUTE_GROUP_VISIBLE() platform/x86/dell: alienware-wmi: update sysfs visibility macros
sysfs: Remove transitional attribute group alias macros

 Documentation/filesystems/sysfs.rst           | 244 ++++++++++++++++++
 drivers/pci/doe.c                             |   2 +-
 .../platform/x86/dell/alienware-wmi-base.c    |  23 +-
 .../platform/x86/dell/alienware-wmi-wmax.c    |   7 +-
 drivers/soundwire/sysfs_slave.c               |  32 +--
 include/linux/sysfs.h                         |  46 +++-
 6 files changed, 306 insertions(+), 48 deletions(-)

base-commit: 9c32cda43eb78f78c73aee4aa344b777714e259b

Signature · 1 line
2.43.0