LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com> Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 1/2] kobject: add kobject_read() Date: Tue, 10 Apr 2018 06:53:50 +0000 [thread overview] Message-ID: <87a7ubv9kg.wl%kuninori.morimoto.gx@renesas.com> (raw) In-Reply-To: <87bmerv9ll.wl%kuninori.morimoto.gx@renesas.com> 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
next prev parent reply other threads:[~2018-04-10 6:53 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-04-10 6:53 [PATCH 0/2] add kobject/of_node read() function Kuninori Morimoto 2018-04-10 6:53 ` Kuninori Morimoto [this message] 2018-04-10 7:10 ` [PATCH 1/2] kobject: add kobject_read() 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=87a7ubv9kg.wl%kuninori.morimoto.gx@renesas.com \ --to=kuninori.morimoto.gx@renesas.com \ --cc=devicetree@vger.kernel.org \ --cc=frowand.list@gmail.com \ --cc=gregkh@linuxfoundation.org \ --cc=linux-kernel@vger.kernel.org \ --cc=robh+dt@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).