Skip to contentSkip to conversation

kobject: introduce kobject_del_and_put()

PATCH Superseded Yangtao Li 3 participants 3 messages Mar 18, 2023 – Mar 19, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 kobject: introduce kobject_del_and_put()

There are plenty of using kobject_del() and kobject_put() together in the kernel tree. This patch wraps these two calls in a single helper.

---
 include/linux/kobject.h |  1 +
 lib/kobject.c           | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
include/linux/kobject.h +1 -0
index bdab370a24f4..782d4bd119f8 100644
@@ -111,6 +111,7 @@ extern struct kobject *kobject_get(struct kobject *kobj);
 extern struct kobject * __must_check kobject_get_unless_zero(
 						struct kobject *kobj);
 extern void kobject_put(struct kobject *kobj);
+extern void kobject_del_and_put(struct kobject *kobj);
 
 extern const void *kobject_namespace(const struct kobject *kobj);
 extern void kobject_get_ownership(const struct kobject *kobj,
lib/kobject.c +15 -2
index 6e2f0bee3560..8c0293e37214 100644
@@ -731,6 +731,20 @@ void kobject_put(struct kobject *kobj)
 }
 EXPORT_SYMBOL(kobject_put);
 
+/**
+ * kobject_del_and_put() - Delete kobject.
+ * @kobj: object.
+ *
+ * Unlink kobject from hierarchy and decrement the refcount.
+ * If refcount is 0, call kobject_cleanup().
+ */
+void kobject_del_and_put(struct kobject *kobj)
+{
+	kobject_del(kobj);
+	kobject_put(kobj);
+}
+EXPORT_SYMBOL_GPL(kobject_del_and_put);
+
 static void dynamic_kobj_release(struct kobject *kobj)
 {
 	pr_debug("kobject: (%p): %s\n", kobj, __func__);
@@ -874,8 +888,7 @@ void kset_unregister(struct kset *k)
 {
 	if (!k)
 		return;
-	kobject_del(&k->kobj);
-	kobject_put(&k->kobj);
+	kobject_del_and_put(&k->kobj);
 }
 EXPORT_SYMBOL(kset_unregister);
 
Signature · 1 line
2.35.1
#1 lore raw
Quoted 32 lines · Yangtao Li

There are plenty of using kobject_del() and kobject_put() together in the kernel tree. This patch wraps these two calls in a single helper.

---
 include/linux/kobject.h |  1 +
 lib/kobject.c           | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
include/linux/kobject.h +1 -0
index bdab370a24f4..782d4bd119f8 100644
@@ -111,6 +111,7 @@ extern struct kobject *kobject_get(struct kobject *kobj);
 extern struct kobject * __must_check kobject_get_unless_zero(
 						struct kobject *kobj);
 extern void kobject_put(struct kobject *kobj);
+extern void kobject_del_and_put(struct kobject *kobj);
 
 extern const void *kobject_namespace(const struct kobject *kobj);
 extern void kobject_get_ownership(const struct kobject *kobj,
lib/kobject.c +3 -0
index 6e2f0bee3560..8c0293e37214 100644
@@ -731,6 +731,20 @@ void kobject_put(struct kobject *kobj)
 }
 EXPORT_SYMBOL(kobject_put);
 
+/**
+ * kobject_del_and_put() - Delete kobject.
+ * @kobj: object.

lib/kobject.c void kobject_put(struct kobject *kobj) · line 746

Quoted 10 lines
lib/kobject.c +10 -0
+ *
+ * Unlink kobject from hierarchy and decrement the refcount.
+ * If refcount is 0, call kobject_cleanup().
+ */
+void kobject_del_and_put(struct kobject *kobj)
+{
+	kobject_del(kobj);
+	kobject_put(kobj);
+}
+EXPORT_SYMBOL_GPL(kobject_del_and_put);

We can't add exports or new functions like this without real users at the same time, otherwise the export will quickly be removed.

So can you submit this as part of a patch series that actually uses it so we can see if it's really even needed?

thanks,

greg k-h

#2 lore raw
In reply to Yangtao Li

From: Yangtao Li <[email protected]>

Quoted 4 lines

Sent: 18 March 2023 20:17

There are plenty of using kobject_del() and kobject_put() together in the kernel tree. This patch wraps these two calls in a single helper.

But why?
You are adding an extra function call for no benefit. At best, perhaps, a static inline function.

David

...

Quoted 21 lines
lib/kobject.c +8 -3
+void kobject_del_and_put(struct kobject *kobj)
+{
+	kobject_del(kobj);
+	kobject_put(kobj);
+}
+EXPORT_SYMBOL_GPL(kobject_del_and_put);
+
 static void dynamic_kobj_release(struct kobject *kobj)
 {
 	pr_debug("kobject: (%p): %s\n", kobj, __func__);
@@ -874,8 +888,7 @@ void kset_unregister(struct kset *k)
 {
 	if (!k)
 		return;
-	kobject_del(&k->kobj);
-	kobject_put(&k->kobj);
+	kobject_del_and_put(&k->kobj);
 }
 EXPORT_SYMBOL(kset_unregister);
 
--
Quoted 1 line

2.35.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)