devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] of: dynamic: add lifecycle docbook info to node creation functions
Date: Mon, 13 Feb 2023 12:57:02 -0600	[thread overview]
Message-ID: <20230213185702.395776-8-frowand.list@gmail.com> (raw)
In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com>

The existing docbook comments for the functions related to creating
a devicetree node do not explain the reference count of a newly
created node, how decrementing the reference count to zero will
free the associated memory, and the caller's responsibility to
call of_node_put() on the node.  Explain what happens when the
reference count is decremented to zero.

Signed-off-by: Frank Rowand <frowand.list@gmail.com>
---
 drivers/of/dynamic.c |  3 ++-
 include/linux/of.h   | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 657a65006056..12aa99018969 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -443,7 +443,8 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
  * another node.  The node data are dynamically allocated and all the node
  * flags have the OF_DYNAMIC & OF_DETACHED bits set.
  *
- * Return: The newly allocated node or NULL on out of memory error.
+ * Return: The newly allocated node or NULL on out of memory error.  Use
+ * of_node_put() on it when done to free the memory allocated for it.
  */
 struct device_node *__of_node_dup(const struct device_node *np,
 				  const char *full_name)
diff --git a/include/linux/of.h b/include/linux/of.h
index 8b9f94386dc3..e20a08c8a8c8 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -100,6 +100,17 @@ struct of_reconfig_data {
 	struct property		*old_prop;
 };
 
+/**
+ * of_node_init - initialize a devicetree node
+ * @node: Pointer to device node that has been created by kzalloc()
+ * @phandle_name: Name of property holding a phandle value
+ *
+ * On return the device_node refcount is set to one.  Use of_node_put()
+ * on @node when done to free the memory allocated for it.  If the node
+ * is NOT a dynamic node the memory will not be freed. The decision of
+ * whether to free the memory will be done by node->release(), which is
+ * of_node_release().
+ */
 /* initialize a node */
 extern struct kobj_type of_node_ktype;
 extern const struct fwnode_operations of_fwnode_ops;
-- 
Frank Rowand <frowand.list@gmail.com>


  parent reply	other threads:[~2023-02-13 18:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13 18:56 [PATCH 0/7] of: unittest: new node lifecycle tests Frank Rowand
2023-02-13 18:56 ` [PATCH 1/7] of: prepare to add processing of EXPECT_NOT to of_unittest_expect Frank Rowand
2023-02-13 18:56 ` [PATCH 2/7] of: " Frank Rowand
2023-02-13 18:56 ` [PATCH 3/7] of: update kconfig unittest help Frank Rowand
2023-02-13 18:56 ` [PATCH 4/7] of: unittest: add node lifecycle tests Frank Rowand
2023-02-26  0:07   ` Guenter Roeck
2023-02-26 19:50     ` Frank Rowand
2023-02-26 21:42     ` Frank Rowand
2023-02-13 18:57 ` [PATCH 5/7] of: do not use "%pOF" printk format on node with refcount of zero Frank Rowand
2023-02-13 19:23   ` Frank Rowand
2023-02-13 19:27     ` Frank Rowand
2023-02-13 18:57 ` [PATCH 6/7] of: add consistency check to of_node_release() Frank Rowand
2023-02-13 18:57 ` Frank Rowand [this message]
2023-02-17 21:44 ` [PATCH 0/7] of: unittest: new node lifecycle tests Rob Herring

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=20230213185702.395776-8-frowand.list@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=devicetree@vger.kernel.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: link
Be 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).