Skip to content

Commit 7dd9fdb

Browse files
t-8chgregkh
authored andcommitted
sysfs: attribute_group: enable const variants of is_visible()
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> Link: https://patch.msgid.link/20251029-sysfs-const-attr-prep-v5-4-ea7d745acff4@weissschuh.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 02ac533 commit 7dd9fdb

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

fs/sysfs/group.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ static umode_t __first_visible(const struct attribute_group *grp, struct kobject
3636
if (grp->attrs && grp->attrs[0] && grp->is_visible)
3737
return grp->is_visible(kobj, grp->attrs[0], 0);
3838

39+
if (grp->attrs && grp->attrs[0] && grp->is_visible_const)
40+
return grp->is_visible_const(kobj, grp->attrs[0], 0);
41+
3942
if (grp->bin_attrs && grp->bin_attrs[0] && grp->is_bin_visible)
4043
return grp->is_bin_visible(kobj, grp->bin_attrs[0], 0);
4144

@@ -61,8 +64,11 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
6164
*/
6265
if (update)
6366
kernfs_remove_by_name(parent, (*attr)->name);
64-
if (grp->is_visible) {
65-
mode = grp->is_visible(kobj, *attr, i);
67+
if (grp->is_visible || grp->is_visible_const) {
68+
if (grp->is_visible)
69+
mode = grp->is_visible(kobj, *attr, i);
70+
else
71+
mode = grp->is_visible_const(kobj, *attr, i);
6672
mode &= ~SYSFS_GROUP_INVISIBLE;
6773
if (!mode)
6874
continue;

include/linux/sysfs.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ do { \
104104
*/
105105
struct attribute_group {
106106
const char *name;
107-
umode_t (*is_visible)(struct kobject *,
108-
struct attribute *, int);
107+
__SYSFS_FUNCTION_ALTERNATIVE(
108+
umode_t (*is_visible)(struct kobject *,
109+
struct attribute *, int);
110+
umode_t (*is_visible_const)(struct kobject *,
111+
const struct attribute *, int);
112+
);
109113
umode_t (*is_bin_visible)(struct kobject *,
110114
const struct bin_attribute *, int);
111115
size_t (*bin_size)(struct kobject *,

0 commit comments

Comments
 (0)