[PATCH 0/4] sysfs: support SYSFS_GROUP_INVISIBLE for unnamed groups and ownership updates
From: Dmitry Torokhov
Date: Mon Nov 16 2026 - 04:43:06 EST
DEFINE_SYSFS_GROUP_VISIBLE() and DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE()
evaluate the group visibility callback only for the first attribute and
return SYSFS_GROUP_INVISIBLE when the entire group should be hidden.
While internal_create_group() checks for this return value before
creating or updating a named group's subdirectory, it skips that check
for unnamed attribute groups and proceeds directly to create_files(). As
a result, returning SYSFS_GROUP_INVISIBLE for an unnamed group only
skips the first attribute while still creating all remaining regular and
binary attributes, and leaves them behind on sysfs_update_group().
In addition, sysfs_group_change_owner() checks SYSFS_GROUP_INVISIBLE too
late inside sysfs_group_attrs_change_owner(), failing with -ENOENT when
looking up the nonexistent subdirectory of a hidden named group and
falling through to binary attributes when breaking out of the regular
attributes loop. Furthermore, SYSFS_GROUP_INVISIBLE is currently tested
and masked with bitwise operations even though it is a standalone
sentinel value rather than a permission bit.
Switch SYSFS_GROUP_INVISIBLE checks to equality comparisons, and check
group visibility upfront in both sysfs_group_change_owner() and
internal_create_group() for named and unnamed groups alike. Drop the
now-redundant SYSFS_GROUP_INVISIBLE checks from create_files() so that
returning it for attributes after the first one triggers the
invalid-permissions warning, and simplify error cleanup in
create_files().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
Dmitry Torokhov (4):
sysfs: check for SYSFS_GROUP_INVISIBLE using equality comparison
sysfs: check group visibility upfront in sysfs_group_change_owner()
sysfs: support SYSFS_GROUP_INVISIBLE for unnamed attribute groups
sysfs: simplify error handling in create_files()
fs/sysfs/group.c | 93 ++++++++++++++++++++++++++++-----------------------
include/linux/sysfs.h | 52 ++++++++++++++++------------
2 files changed, 81 insertions(+), 64 deletions(-)
---
base-commit: 84abb955b1015477aa11a96e2f3ac1b938b77f48
change-id: 20261115-sysfs-group-invisible-443ba270fd0a
Thanks.
--
Dmitry