LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] add kobject/of_node read() function
@ 2018-04-10 6:53 Kuninori Morimoto
2018-04-10 6:53 ` [PATCH 1/2] kobject: add kobject_read() Kuninori Morimoto
2018-04-10 6:54 ` [PATCH 2/2] of: add of_node_read() Kuninori Morimoto
0 siblings, 2 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2018-04-10 6:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rob Herring, Frank Rowand; +Cc: linux-kernel, devicetree
Hi Greg, Rob, Frank
We are using {kobject_/of_node_}get/put() for increment/decrement
counter. But, because we don't have counter read() function,
confirming it (mainly for debug purpose) is a little bit difficult.
These patches add read() function for it.
Kuninori Morimoto (2):
kobject: add kobject_read()
of: add of_node_read()
drivers/of/dynamic.c | 14 ++++++++++++++
include/linux/kobject.h | 1 +
include/linux/of.h | 5 +++++
lib/kobject.c | 18 ++++++++++++++++++
4 files changed, 38 insertions(+)
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] kobject: add kobject_read()
2018-04-10 6:53 [PATCH 0/2] add kobject/of_node read() function Kuninori Morimoto
@ 2018-04-10 6:53 ` Kuninori Morimoto
2018-04-10 7:10 ` Greg Kroah-Hartman
2018-04-10 6:54 ` [PATCH 2/2] of: add of_node_read() Kuninori Morimoto
1 sibling, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2018-04-10 6:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rob Herring, Frank Rowand; +Cc: linux-kernel, devicetree
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.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@renesas.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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] of: add of_node_read()
2018-04-10 6:53 [PATCH 0/2] add kobject/of_node read() function Kuninori Morimoto
2018-04-10 6:53 ` [PATCH 1/2] kobject: add kobject_read() Kuninori Morimoto
@ 2018-04-10 6:54 ` Kuninori Morimoto
2018-04-10 7:11 ` Greg Kroah-Hartman
1 sibling, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2018-04-10 6:54 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rob Herring, Frank Rowand; +Cc: linux-kernel, devicetree
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
We are counting of node by using of_node_get/put(), but
not have of_node_read() which can be used to check count.
Let's add it
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
drivers/of/dynamic.c | 14 ++++++++++++++
include/linux/of.h | 5 +++++
2 files changed, 19 insertions(+)
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index f4f8ed9..db5fdf3 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -49,6 +49,20 @@ void of_node_put(struct device_node *node)
}
EXPORT_SYMBOL(of_node_put);
+/**
+ * of_node_read() - read refcount of a node
+ * @node: Node to dec refcount, NULL is supported to simplify writing of
+ * callers
+ */
+unsigned int of_node_read(struct device_node *node)
+{
+ if (node)
+ return kobject_read(&node->kobj);
+
+ return 0;
+}
+EXPORT_SYMBOL(of_node_read);
+
static BLOCKING_NOTIFIER_HEAD(of_reconfig_chain);
int of_reconfig_notifier_register(struct notifier_block *nb)
diff --git a/include/linux/of.h b/include/linux/of.h
index 4d25e4f..8be0ca8 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -122,6 +122,7 @@ static inline void of_node_init(struct device_node *node)
#ifdef CONFIG_OF_DYNAMIC
extern struct device_node *of_node_get(struct device_node *node);
extern void of_node_put(struct device_node *node);
+unsigned int of_node_read(struct device_node *node);
#else /* CONFIG_OF_DYNAMIC */
/* Dummy ref counting routines - to be implemented later */
static inline struct device_node *of_node_get(struct device_node *node)
@@ -129,6 +130,10 @@ static inline struct device_node *of_node_get(struct device_node *node)
return node;
}
static inline void of_node_put(struct device_node *node) { }
+static inline unsigned int of_node_read(struct device_node *node)
+{
+ return 0;
+}
#endif /* !CONFIG_OF_DYNAMIC */
/* Pointer for first entry in chain of all nodes. */
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] kobject: add kobject_read()
2018-04-10 6:53 ` [PATCH 1/2] kobject: add kobject_read() Kuninori Morimoto
@ 2018-04-10 7:10 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2018-04-10 7:10 UTC (permalink / raw)
To: Kuninori Morimoto; +Cc: Rob Herring, Frank Rowand, linux-kernel, devicetree
On Tue, Apr 10, 2018 at 06:53:50AM +0000, Kuninori Morimoto wrote:
>
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.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
No, please do not. You should never care about this "count", and if we
do provide this, people will abuse it.
I understand that this might make some debugging harder, but if you
really need to write custom debugging code, then just use the internal
values.
sorry,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] of: add of_node_read()
2018-04-10 6:54 ` [PATCH 2/2] of: add of_node_read() Kuninori Morimoto
@ 2018-04-10 7:11 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2018-04-10 7:11 UTC (permalink / raw)
To: Kuninori Morimoto; +Cc: Rob Herring, Frank Rowand, linux-kernel, devicetree
On Tue, Apr 10, 2018 at 06:54:13AM +0000, Kuninori Morimoto wrote:
>
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
>
> We are counting of node by using of_node_get/put(), but
> not have of_node_read() which can be used to check count.
> Let's add it
Same objection as previous patch, please no.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-10 7:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 6:53 [PATCH 0/2] add kobject/of_node read() function Kuninori Morimoto
2018-04-10 6:53 ` [PATCH 1/2] kobject: add kobject_read() Kuninori Morimoto
2018-04-10 7:10 ` Greg Kroah-Hartman
2018-04-10 6:54 ` [PATCH 2/2] of: add of_node_read() Kuninori Morimoto
2018-04-10 7:11 ` 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).