lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 23 Mar 2023 00:58:30 +0800
From:   Yangtao Li <frank.li@...o.com>
To:     clm@...com, josef@...icpanda.com, dsterba@...e.com,
        xiang@...nel.org, chao@...nel.org, huyue2@...lpad.com,
        jefflexu@...ux.alibaba.com, jaegeuk@...nel.org,
        trond.myklebust@...merspace.com, anna@...nel.org,
        konishi.ryusuke@...il.com, mark@...heh.com, jlbec@...lplan.org,
        joseph.qi@...ux.alibaba.com, richard@....at, djwong@...nel.org,
        damien.lemoal@...nsource.wdc.com, naohiro.aota@....com,
        jth@...nel.org, gregkh@...uxfoundation.org, rafael@...nel.org
Cc:     linux-btrfs@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-erofs@...ts.ozlabs.org,
        linux-f2fs-devel@...ts.sourceforge.net, linux-nfs@...r.kernel.org,
        linux-nilfs@...r.kernel.org, ocfs2-devel@....oracle.com,
        linux-mtd@...ts.infradead.org, linux-xfs@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, Yangtao Li <frank.li@...o.com>
Subject: [PATCH v3 01/10] 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.

Signed-off-by: Yangtao Li <frank.li@...o.com>
---
v3:
-convert to inline helper
v2:
-add kobject_del_and_put() users
 include/linux/kobject.h | 13 +++++++++++++
 lib/kobject.c           |  3 +--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bdab370a24f4..e21b7c22e355 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -112,6 +112,19 @@ extern struct kobject * __must_check kobject_get_unless_zero(
 						struct kobject *kobj);
 extern void kobject_put(struct kobject *kobj);
 
+/**
+ * kobject_del_and_put() - Delete kobject.
+ * @kobj: object.
+ *
+ * Unlink kobject from hierarchy and decrement the refcount.
+ * If refcount is 0, call kobject_cleanup().
+ */
+static inline void kobject_del_and_put(struct kobject *kobj)
+{
+	kobject_del(kobj);
+	kobject_put(kobj);
+}
+
 extern const void *kobject_namespace(const struct kobject *kobj);
 extern void kobject_get_ownership(const struct kobject *kobj,
 				  kuid_t *uid, kgid_t *gid);
diff --git a/lib/kobject.c b/lib/kobject.c
index f79a434e1231..e6c5a3ff1c53 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -876,8 +876,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);
 
-- 
2.35.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ