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 5/7] of: do not use "%pOF" printk format on node with refcount of zero
Date: Mon, 13 Feb 2023 12:57:00 -0600 [thread overview]
Message-ID: <20230213185702.395776-6-frowand.list@gmail.com> (raw)
In-Reply-To: <20230213185702.395776-1-frowand.list@gmail.com>
of_node_release() can not use the "%pOF" printk format to report
the node name of a node when the node reference count is zero.
This is because the formatter device_node_string() calls
fwnode_full_name_string() which indirectly calls of_node_get().
Calling of_node_get() on the node with a zero reference count
results in a WARNING and stack trace.
When the reference count has been decremented to zero, this function
is in the subsequent call path which frees memory related to the node.
This commit resolves the unittest EXPECT errors that were created in
the previous commmit.
Signed-off-by: Frank Rowand <frowand.list@gmail.com>
---
The scripts/dtc/of_unittest_expect summary statistics before this commit:
** EXPECT statistics:
**
** non-zero values expected:
**
** EXPECT found : 50
** EXPECT_NOT not found : 4
**
** zero values expected:
**
** EXPECT not found : 0
** missing EXPECT begin : 5
** missing EXPECT end : 0
**
** EXPECT_NOT found : 0
** missing EXPECT_NOT begin : 0
** missing EXPECT_NOT end : 0
**
** unittest FAIL : 0
** internal error : 0
The scripts/dtc/of_unittest_expect summary statistics after this commit:
** EXPECT statistics:
**
** non-zero values expected:
**
** EXPECT found : 55
** EXPECT_NOT not found : 4
**
** zero values expected:
**
** EXPECT not found : 0
** missing EXPECT begin : 0
** missing EXPECT end : 0
**
** EXPECT_NOT found : 0
** missing EXPECT_NOT begin : 0
** missing EXPECT_NOT end : 0
**
** unittest FAIL : 0
** internal error : 0
drivers/of/dynamic.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index becb80f762c8..dbcbc41f3465 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -329,9 +329,17 @@ void of_node_release(struct kobject *kobj)
{
struct device_node *node = kobj_to_device_node(kobj);
+ /*
+ * can not use '"%pOF", node' in pr_err() calls from this function
+ * because an of_node_get(node) when refcount is already zero
+ * will result in an error and a stack dump
+ */
+
/* We should never be releasing nodes that haven't been detached. */
if (!of_node_check_flag(node, OF_DETACHED)) {
- pr_err("ERROR: Bad of_node_put() on %pOF\n", node);
+
+ pr_err("ERROR: %s() detected bad of_node_put() on %pOF/%s\n",
+ __func__, node->parent, node->full_name);
/*
* of unittests will test this path. Do not print the stack
--
Frank Rowand <frowand.list@gmail.com>
next prev parent reply other threads:[~2023-02-13 18:57 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 ` Frank Rowand [this message]
2023-02-13 19:23 ` [PATCH 5/7] of: do not use "%pOF" printk format on node with refcount of zero 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 ` [PATCH 7/7] of: dynamic: add lifecycle docbook info to node creation functions Frank Rowand
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-6-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).