[v2,01/10] kobject: introduce kobject_del_and_put()

Message ID 20230319084134.11804-1-frank.li@vivo.com
State New
Headers
Series [v2,01/10] kobject: introduce kobject_del_and_put() |

Commit Message

李扬韬 March 19, 2023, 8:41 a.m. UTC
  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.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
v2:
-add kobject_del_and_put() users
 include/linux/kobject.h |  1 +
 lib/kobject.c           | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
  

Comments

Greg KH March 19, 2023, 9:08 a.m. UTC | #1
On Sun, Mar 19, 2023 at 04:41:24PM +0800, Yangtao Li wrote:
> 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.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> v2:
> -add kobject_del_and_put() users
>  include/linux/kobject.h |  1 +
>  lib/kobject.c           | 17 +++++++++++++++--
>  2 files changed, 16 insertions(+), 2 deletions(-)

Any reason you only sent me one patch?  I guess you don't want me to
review them?  :(
  
李扬韬 March 19, 2023, 9:36 a.m. UTC | #2
> Any reason you only sent me one patch?  I guess you don't want me to
> review them?  :(

Sorry, I used the following git configuration to send emails, so it was
not sent to you.

[sendemail]
    tocmd ="`pwd`/scripts/get_maintainer.pl --nogit --nogit-fallback --norolestats --nol"
    cccmd ="`pwd`/scripts/get_maintainer.pl --nogit --nogit-fallback --norolestats --nom"

I amended the resent patch, the patch body states cc to you and Rafael.

Thx,
Yangtao
  
Greg KH March 19, 2023, 10:06 a.m. UTC | #3
On Sun, Mar 19, 2023 at 05:36:36PM +0800, Yangtao Li wrote:
> > Any reason you only sent me one patch?  I guess you don't want me to
> > review them?  :(
> 
> Sorry, I used the following git configuration to send emails, so it was
> not sent to you.
> 
> [sendemail]
>     tocmd ="`pwd`/scripts/get_maintainer.pl --nogit --nogit-fallback --norolestats --nol"
>     cccmd ="`pwd`/scripts/get_maintainer.pl --nogit --nogit-fallback --norolestats --nom"
> 
> I amended the resent patch, the patch body states cc to you and Rafael.

Great, thanks, I got them now, I'll queue them up later next week if
there's no complaints.

greg k-h
  

Patch

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bdab370a24f4..782d4bd119f8 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -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,
diff --git a/lib/kobject.c b/lib/kobject.c
index 6e2f0bee3560..8c0293e37214 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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);