Skip to content

Commit aa30f47

Browse files
kbrown9gregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0b777ee commit aa30f47

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/linux/kobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ static inline bool kobject_has_children(struct kobject *kobj)
139139
struct kobj_type {
140140
void (*release)(struct kobject *kobj);
141141
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;
143144
const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
144145
const void *(*namespace)(struct kobject *kobj);
145146
void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid);

lib/kobject.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static int populate_dir(struct kobject *kobj)
8282

8383
static int create_dir(struct kobject *kobj)
8484
{
85+
const struct kobj_type *ktype = get_ktype(kobj);
8586
const struct kobj_ns_type_operations *ops;
8687
int error;
8788

@@ -95,6 +96,14 @@ static int create_dir(struct kobject *kobj)
9596
return error;
9697
}
9798

99+
if (ktype) {
100+
error = sysfs_create_groups(kobj, ktype->default_groups);
101+
if (error) {
102+
sysfs_remove_dir(kobj);
103+
return error;
104+
}
105+
}
106+
98107
/*
99108
* @kobj->sd may be deleted by an ancestor going away. Hold an
100109
* extra reference so that it stays until @kobj is gone.
@@ -584,11 +593,16 @@ EXPORT_SYMBOL_GPL(kobject_move);
584593
void kobject_del(struct kobject *kobj)
585594
{
586595
struct kernfs_node *sd;
596+
const struct kobj_type *ktype = get_ktype(kobj);
587597

588598
if (!kobj)
589599
return;
590600

591601
sd = kobj->sd;
602+
603+
if (ktype)
604+
sysfs_remove_groups(kobj, ktype->default_groups);
605+
592606
sysfs_remove_dir(kobj);
593607
sysfs_put(sd);
594608

0 commit comments

Comments
 (0)