[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87a7ubv9kg.wl%kuninori.morimoto.gx@renesas.com>
Date: Tue, 10 Apr 2018 06:53:50 +0000
From: Kuninori Morimoto <kuninori.morimoto.gx@...esas.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>
Cc: linux-kernel@...r.kernel.org, devicetree@...r.kernel.org
Subject: [PATCH 1/2] kobject: add kobject_read()
From: Kuninori Morimoto <kuninori.morimoto.gx@...esas.com>
We are counting kobject by using kobject_get/put(), but
not have kobject_read() which can be used to check count.
Let's add
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@...esas.com>
---
include/linux/kobject.h | 1 +
lib/kobject.c | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 7f6f93c..6f74d4b 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -108,6 +108,7 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,
extern int __must_check kobject_rename(struct kobject *, const char *new_name);
extern int __must_check kobject_move(struct kobject *, struct kobject *);
+extern unsigned int kobject_read(struct kobject *kobj);
extern struct kobject *kobject_get(struct kobject *kobj);
extern struct kobject * __must_check kobject_get_unless_zero(
struct kobject *kobj);
diff --git a/lib/kobject.c b/lib/kobject.c
index afd5a3f..103c8c8 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -561,6 +561,24 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
EXPORT_SYMBOL_GPL(kobject_move);
/**
+ * kobject_read - read refcount count for object.
+ * @kobj: object.
+ */
+unsigned int kobject_read(struct kobject *kobj)
+{
+ if (kobj) {
+ if (!kobj->state_initialized)
+ WARN(1, KERN_WARNING "kobject: '%s' (%p): is not "
+ "initialized, yet kobject_put() is being "
+ "called.\n", kobject_name(kobj), kobj);
+ return kref_read(&kobj->kref);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(kobject_read);
+
+/**
* kobject_del - unlink kobject from hierarchy.
* @kobj: object.
*/
--
1.9.1
Powered by blists - more mailing lists