[PATCH v3 4/7] sysfs: attribute_group: enable const variants of is_visible()

Thomas Weißschuh posted 7 patches 1 month, 3 weeks ago
[PATCH v3 4/7] sysfs: attribute_group: enable const variants of is_visible()
Posted by Thomas Weißschuh 1 month, 3 weeks ago
When constifying instances of struct attribute, for consistency the
corresponding .is_visible() callback should be adapted, too.
Introduce a temporary transition mechanism until all callbacks are
converted.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 fs/sysfs/group.c      | 10 ++++++++--
 include/linux/sysfs.h |  8 ++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 2d78e94072a0d4ed957560c60cc3c5dd49ab6fb4..d514ce8ac4d964676006dc45a31bb9f5fe5fd5dd 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -36,6 +36,9 @@ static umode_t __first_visible(const struct attribute_group *grp, struct kobject
 	if (grp->attrs && grp->attrs[0] && grp->is_visible)
 		return grp->is_visible(kobj, grp->attrs[0], 0);
 
+	if (grp->attrs && grp->attrs[0] && grp->is_visible_new)
+		return grp->is_visible_new(kobj, grp->attrs[0], 0);
+
 	if (grp->bin_attrs && grp->bin_attrs[0] && grp->is_bin_visible)
 		return grp->is_bin_visible(kobj, grp->bin_attrs[0], 0);
 
@@ -61,8 +64,11 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 			 */
 			if (update)
 				kernfs_remove_by_name(parent, (*attr)->name);
-			if (grp->is_visible) {
-				mode = grp->is_visible(kobj, *attr, i);
+			if (grp->is_visible || grp->is_visible_new) {
+				if (grp->is_visible)
+					mode = grp->is_visible(kobj, *attr, i);
+				else
+					mode = grp->is_visible_new(kobj, *attr, i);
 				mode &= ~SYSFS_GROUP_INVISIBLE;
 				if (!mode)
 					continue;
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 3966947e78b8c030971daf5ee66bf5ab40bc2a17..1807b0369bd4d993deab81c4497903468b751a19 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -104,8 +104,12 @@ do {							\
  */
 struct attribute_group {
 	const char		*name;
-	umode_t			(*is_visible)(struct kobject *,
-					      struct attribute *, int);
+	__SYSFS_FUNCTION_ALTERNATIVE(
+		umode_t			(*is_visible)(struct kobject *,
+						      struct attribute *, int);
+		umode_t			(*is_visible_new)(struct kobject *,
+							  const struct attribute *, int);
+	);
 	umode_t			(*is_bin_visible)(struct kobject *,
 						  const struct bin_attribute *, int);
 	size_t			(*bin_size)(struct kobject *,

-- 
2.50.1

Re: [PATCH v3 4/7] sysfs: attribute_group: enable const variants of is_visible()
Posted by Greg Kroah-Hartman 1 month, 2 weeks ago
On Mon, Aug 11, 2025 at 11:14:30AM +0200, Thomas Weißschuh wrote:
> When constifying instances of struct attribute, for consistency the
> corresponding .is_visible() callback should be adapted, too.
> Introduce a temporary transition mechanism until all callbacks are
> converted.

I count about 600+ users of is_visible() now, how is that going to be
converted?  It feels like a lot of churn/work, what's the plan here?

These changes seem a lot more intrusive than the bin_attr ones :(

thanks,

greg k-h
Re: [PATCH v3 4/7] sysfs: attribute_group: enable const variants of is_visible()
Posted by Thomas Weißschuh 1 month, 2 weeks ago
On 2025-08-19 13:28:40+0200, Greg Kroah-Hartman wrote:
> On Mon, Aug 11, 2025 at 11:14:30AM +0200, Thomas Weißschuh wrote:
> > When constifying instances of struct attribute, for consistency the
> > corresponding .is_visible() callback should be adapted, too.
> > Introduce a temporary transition mechanism until all callbacks are
> > converted.
> 
> I count about 600+ users of is_visible() now, how is that going to be
> converted?  It feels like a lot of churn/work, what's the plan here?

The idea was to convert one driver at a time to the const variants.
Adapting is_visible(), read(), write() and the group structs
together. And then submit these batched per subsystem.
It's not a purely mechanical change as the users may modify their
attributes.

It will be a lot of churn. is_visible() is not even the big one.

> These changes seem a lot more intrusive than the bin_attr ones :(

Indeed :-/


Thomas