[PATCH 1/4] sysfs: check for SYSFS_GROUP_INVISIBLE using equality comparison

From: Dmitry Torokhov

Date: Mon Nov 16 2026 - 04:43:13 EST


Unlike SYSFS_PREALLOC, which is a permission modifier bit OR'd with a
file mode, SYSFS_GROUP_INVISIBLE is a standalone sentinel return value
indicating that the entire attribute group should be hidden.

Replace bitwise checks and flag masking of SYSFS_GROUP_INVISIBLE with
direct equality comparisons so that any invalid combination of
SYSFS_GROUP_INVISIBLE with permission bits is not silently accepted and
instead triggers the invalid-permissions warning.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
fs/sysfs/group.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 4e1e4f18a166..cc03229f8a94 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -69,8 +69,7 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
mode = grp->is_visible(kobj, *attr, i);
else
mode = grp->is_visible_const(kobj, *attr, i);
- mode &= ~SYSFS_GROUP_INVISIBLE;
- if (!mode)
+ if (!mode || mode == SYSFS_GROUP_INVISIBLE)
continue;
}

@@ -100,8 +99,7 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
(*bin_attr)->attr.name);
if (grp->is_bin_visible) {
mode = grp->is_bin_visible(kobj, *bin_attr, i);
- mode &= ~SYSFS_GROUP_INVISIBLE;
- if (!mode)
+ if (!mode || mode == SYSFS_GROUP_INVISIBLE)
continue;
}
if (grp->bin_size)
@@ -151,7 +149,7 @@ static int internal_create_group(struct kobject *kobj, int update,
if (grp->name) {
umode_t mode = __first_visible(grp, kobj);

- if (mode & SYSFS_GROUP_INVISIBLE)
+ if (mode == SYSFS_GROUP_INVISIBLE)
mode = 0;
else
mode = S_IRWXU | S_IRUGO | S_IXUGO;
@@ -522,7 +520,7 @@ static int sysfs_group_attrs_change_owner(struct kobject *kobj,
mode = grp->is_visible(kobj, *attr, i);
else
mode = grp->is_visible_const(kobj, *attr, i);
- if (mode & SYSFS_GROUP_INVISIBLE)
+ if (mode == SYSFS_GROUP_INVISIBLE)
break;
if (!mode)
continue;
@@ -544,7 +542,7 @@ static int sysfs_group_attrs_change_owner(struct kobject *kobj,
for (i = 0, bin_attr = grp->bin_attrs; *bin_attr; i++, bin_attr++) {
if (grp->is_bin_visible) {
mode = grp->is_bin_visible(kobj, *bin_attr, i);
- if (mode & SYSFS_GROUP_INVISIBLE)
+ if (mode == SYSFS_GROUP_INVISIBLE)
break;
if (!mode)
continue;

--
2.56.0.679.gc527c65306-goog