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

kobject: Add support for default attribute groups to kobj_type

kobj_type currently uses a list of individual attributes to store
default attributes. Attribute groups are more flexible than a list of
attributes because groups provide support for attribute visibility. So,
add support for default attribute groups to kobj_type.

In future patches, the existing uses of kobj_type’s attribute list will
be converted to attribute groups. When that is complete, kobj_type’s
attribute list, “default_attrs”, will be removed.

Signed-off-by: Kimberly Brown <kimbrownkd@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kimberly Brown and committed by
Greg Kroah-Hartman
aa30f47c 0b777eee

+16 -1
+2 -1
include/linux/kobject.h
··· 139 139 struct kobj_type { 140 140 void (*release)(struct kobject *kobj); 141 141 const struct sysfs_ops *sysfs_ops; 142 - struct attribute **default_attrs; 142 + struct attribute **default_attrs; /* use default_groups instead */ 143 + const struct attribute_group **default_groups; 143 144 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj); 144 145 const void *(*namespace)(struct kobject *kobj); 145 146 void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid);
+14
lib/kobject.c
··· 82 82 83 83 static int create_dir(struct kobject *kobj) 84 84 { 85 + const struct kobj_type *ktype = get_ktype(kobj); 85 86 const struct kobj_ns_type_operations *ops; 86 87 int error; 87 88 ··· 94 93 if (error) { 95 94 sysfs_remove_dir(kobj); 96 95 return error; 96 + } 97 + 98 + if (ktype) { 99 + error = sysfs_create_groups(kobj, ktype->default_groups); 100 + if (error) { 101 + sysfs_remove_dir(kobj); 102 + return error; 103 + } 97 104 } 98 105 99 106 /* ··· 593 584 void kobject_del(struct kobject *kobj) 594 585 { 595 586 struct kernfs_node *sd; 587 + const struct kobj_type *ktype = get_ktype(kobj); 596 588 597 589 if (!kobj) 598 590 return; 599 591 600 592 sd = kobj->sd; 593 + 594 + if (ktype) 595 + sysfs_remove_groups(kobj, ktype->default_groups); 596 + 601 597 sysfs_remove_dir(kobj); 602 598 sysfs_put(sd); 603 599