From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Fernando Fernandez Mancera <fmancera@suse.de>
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 1/4] sysfs: check for SYSFS_GROUP_INVISIBLE using equality comparison
Date: Mon, 16 Nov 2026 01:42:53 -0800 [thread overview]
Message-ID: <20261116-sysfs-group-invisible-v1-1-94cd173a7d9a@gmail.com> (raw)
In-Reply-To: <20261116-sysfs-group-invisible-v1-0-94cd173a7d9a@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-11-16 9:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 9:42 [PATCH 0/4] sysfs: support SYSFS_GROUP_INVISIBLE for unnamed groups and ownership updates Dmitry Torokhov
2026-11-16 9:42 ` Dmitry Torokhov [this message]
2026-11-16 9:42 ` [PATCH 2/4] sysfs: check group visibility upfront in sysfs_group_change_owner() Dmitry Torokhov
2026-11-16 9:42 ` [PATCH 3/4] sysfs: support SYSFS_GROUP_INVISIBLE for unnamed attribute groups Dmitry Torokhov
2026-11-16 9:42 ` [PATCH 4/4] sysfs: simplify error handling in create_files() Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116-sysfs-group-invisible-v1-1-94cd173a7d9a@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=fmancera@suse.de \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®