Skip to content

Commit c301a2e

Browse files
t-8chgregkh
authored andcommitted
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>
1 parent 7dd9fdb commit c301a2e

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

samples/kobject/kset-example.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,22 @@ static struct attribute *foo_default_attrs[] = {
178178
&bar_attribute.attr,
179179
NULL, /* need to NULL terminate the list of attributes */
180180
};
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);
182197

183198
/*
184199
* Our own ktype for our kobjects. Here we specify our sysfs ops, the

0 commit comments

Comments
 (0)