linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kobject: Add support for default attribute groups to kobj_type
@ 2019-03-22 20:14 Kimberly Brown
  2019-03-23  6:07 ` Greg Kroah-Hartman
  2019-04-02  2:51 ` [PATCH v2 0/8] kobject: Add default group support to kobj_type and replace subsystem uses Kimberly Brown
  0 siblings, 2 replies; 26+ messages in thread
From: Kimberly Brown @ 2019-03-22 20:14 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: linux-kernel

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>
---
 include/linux/kobject.h |  3 ++-
 lib/kobject.c           | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 1ab0d624fb36..e2ca0a292e21 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -139,7 +139,8 @@ static inline bool kobject_has_children(struct kobject *kobj)
 struct kobj_type {
 	void (*release)(struct kobject *kobj);
 	const struct sysfs_ops *sysfs_ops;
-	struct attribute **default_attrs;
+	struct attribute **default_attrs;	/* use default_groups instead */
+	const struct attribute_group **default_groups;
 	const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
 	const void *(*namespace)(struct kobject *kobj);
 	void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid);
diff --git a/lib/kobject.c b/lib/kobject.c
index b72e00fd7d09..67789f34951d 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);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-04-27  6:41 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 20:14 [PATCH] kobject: Add support for default attribute groups to kobj_type Kimberly Brown
2019-03-23  6:07 ` Greg Kroah-Hartman
2019-03-24  3:48   ` Kimberly Brown
2019-03-24  5:15     ` Greg Kroah-Hartman
2019-04-02  2:51 ` [PATCH v2 0/8] kobject: Add default group support to kobj_type and replace subsystem uses Kimberly Brown
2019-04-02  2:51   ` [PATCH v2 1/8] kobject: Add support for default attribute groups to kobj_type Kimberly Brown
2019-04-02  2:51   ` [PATCH v2 2/8] samples/kobject: Replace foo_ktype's default_attrs field with groups Kimberly Brown
2019-04-02  2:51   ` [PATCH v2 3/8] block: Replace all ktype default_attrs " Kimberly Brown
2019-04-02 16:02     ` Bart Van Assche
2019-04-02 17:46       ` Greg Kroah-Hartman
2019-04-02 18:06         ` Bart Van Assche
2019-04-02  2:51   ` [PATCH v2 4/8] net-sysfs: Replace ktype default_attrs field " Kimberly Brown
2019-04-02  2:51   ` [PATCH v2 5/8] irqdesc: Replace irq_kobj_type's " Kimberly Brown
2019-04-02  8:04     ` Thomas Gleixner
2019-04-02  2:51   ` [PATCH v2 6/8] padata: Replace padata_attr_type " Kimberly Brown
2019-04-02  2:51   ` [PATCH v2 7/8] cpufreq: schedutil: Replace " Kimberly Brown
2019-04-02  7:56     ` Rafael J. Wysocki
2019-04-02  8:50     ` Peter Zijlstra
2019-04-02  2:51   ` [PATCH v2 8/8] livepatch: Replace klp_ktype_patch's default_attrs " Kimberly Brown
2019-04-02 10:22     ` Jiri Kosina
2019-04-03 11:51     ` Miroslav Benes
2019-04-08 14:16     ` Petr Mladek
2019-04-02  6:29   ` [PATCH v2 0/8] kobject: Add default group support to kobj_type and replace subsystem uses Greg Kroah-Hartman
2019-04-25 20:12   ` Greg Kroah-Hartman
2019-04-27  6:18     ` Kimberly Brown
2019-04-27  6:41       ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).