summaryrefslogtreecommitdiff
path: root/lib/kobject.c
diff options
context:
space:
mode:
authorKimberly Brown <kimbrownkd@gmail.com>2019-04-01 22:51:18 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-04-25 22:06:10 +0200
commitaa30f47cf666111f6bbfd15f290a27e8a7b9d854 (patch)
treef37b73de916cc982e5fe7b5d0ad5dc70c3bc7702 /lib/kobject.c
parent0b777eee88d712256ba8232a9429edb17c4f9ceb (diff)
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>
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index aa89edcd2b63..ede40005db28 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -82,6 +82,7 @@ static int populate_dir(struct kobject *kobj)
static int create_dir(struct kobject *kobj)
{
+ const struct kobj_type *ktype = get_ktype(kobj);
const struct kobj_ns_type_operations *ops;
int error;
@@ -95,6 +96,14 @@ static int create_dir(struct kobject *kobj)
return error;
}
+ if (ktype) {
+ error = sysfs_create_groups(kobj, ktype->default_groups);
+ if (error) {
+ sysfs_remove_dir(kobj);
+ return error;
+ }
+ }
+
/*
* @kobj->sd may be deleted by an ancestor going away. Hold an
* extra reference so that it stays until @kobj is gone.
@@ -584,11 +593,16 @@ EXPORT_SYMBOL_GPL(kobject_move);
void kobject_del(struct kobject *kobj)
{
struct kernfs_node *sd;
+ const struct kobj_type *ktype = get_ktype(kobj);
if (!kobj)
return;
sd = kobj->sd;
+
+ if (ktype)
+ sysfs_remove_groups(kobj, ktype->default_groups);
+
sysfs_remove_dir(kobj);
sysfs_put(sd);