Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

samples/kobject: add is_visible() callback to attribute group

There was no example for the is_visible() callback so far.

It will also become an example and test for the constification of
'struct attribute' later.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://patch.msgid.link/20251029-sysfs-const-attr-prep-v5-5-ea7d745acff4@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
c301a2e2 7dd9fdb4

+16 -1
+16 -1
samples/kobject/kset-example.c
··· 178 178 &bar_attribute.attr, 179 179 NULL, /* need to NULL terminate the list of attributes */ 180 180 }; 181 - ATTRIBUTE_GROUPS(foo_default); 181 + 182 + static umode_t foo_default_attrs_is_visible(struct kobject *kobj, 183 + struct attribute *attr, 184 + int n) 185 + { 186 + /* Hide attributes with the same name as the kobject. */ 187 + if (strcmp(kobject_name(kobj), attr->name) == 0) 188 + return 0; 189 + return attr->mode; 190 + } 191 + 192 + static const struct attribute_group foo_default_group = { 193 + .attrs = foo_default_attrs, 194 + .is_visible = foo_default_attrs_is_visible, 195 + }; 196 + __ATTRIBUTE_GROUPS(foo_default); 182 197 183 198 /* 184 199 * Our own ktype for our kobjects. Here we specify our sysfs ops, the