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 2/4] sysfs: check group visibility upfront in sysfs_group_change_owner()
Date: Mon, 16 Nov 2026 01:42:54 -0800 [thread overview]
Message-ID: <20261116-sysfs-group-invisible-v1-2-94cd173a7d9a@gmail.com> (raw)
In-Reply-To: <20261116-sysfs-group-invisible-v1-0-94cd173a7d9a@gmail.com>
For hidden named attribute groups, looking up the group subdirectory in
sysfs_group_change_owner() fails with -ENOENT before attribute
visibility is ever checked inside sysfs_group_attrs_change_owner(). In
addition, checking SYSFS_GROUP_INVISIBLE inside
sysfs_group_attrs_change_owner() still updates ownership on the
kobject's own directory node for hidden unnamed groups, and breaking out
of the regular attributes loop still falls through to binary attributes.
Check group visibility upfront in sysfs_group_change_owner() using
__first_visible() and return 0 immediately when SYSFS_GROUP_INVISIBLE is
returned. Remove the now-redundant SYSFS_GROUP_INVISIBLE checks from
sysfs_group_attrs_change_owner(), which has no other callers.
Fixes: c7fbb8218b4a ("sysfs: check visibility before changing group attribute ownership")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
fs/sysfs/group.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index cc03229f8a94..290e70034329 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -520,8 +520,6 @@ 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)
- break;
if (!mode)
continue;
}
@@ -542,8 +540,6 @@ 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)
- break;
if (!mode)
continue;
}
@@ -585,6 +581,9 @@ int sysfs_group_change_owner(struct kobject *kobj,
if (!kobj->state_in_sysfs)
return -EINVAL;
+ if (__first_visible(grp, kobj) == SYSFS_GROUP_INVISIBLE)
+ return 0;
+
if (grp->name) {
grp_kn = kernfs_find_and_get(kobj->sd, grp->name);
} else {
--
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 ` [PATCH 1/4] sysfs: check for SYSFS_GROUP_INVISIBLE using equality comparison Dmitry Torokhov
2026-11-16 9:42 ` Dmitry Torokhov [this message]
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-2-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®