From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Bartosz Golaszewski <brgl@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
linux-acpi@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org, imx@lists.linux.dev,
Peng Fan <peng.fan@nxp.com>
Subject: [PATCH 4/4] software node: skip dying children during traversal
Date: Wed, 04 Nov 2026 23:43:16 +0800 [thread overview]
Message-ID: <20261104-swnode-race-v1-v1-4-9406a67e25be@nxp.com> (raw)
In-Reply-To: <20261104-swnode-race-v1-v1-0-9406a67e25be@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
A child swnode is removed from its parent's children list in
software_node_release(), which runs after its kobject refcount has
already reached zero. The fwnode child traversal helpers can therefore
find an entry that is in its release path and call kobject_get() on a
zero refcount.
Use kobject_get_unless_zero() in software_node_get_next_child() and
software_node_get_named_child_node() and keep scanning until a live
child is found or the list ends.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/base/swnode.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 4d95a59a27f0a..1354447069e10 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -515,7 +515,18 @@ software_node_get_next_child(const struct fwnode_handle *fwnode,
c = list_first_entry(&p->children, struct swnode, entry);
fwnode_handle_put(child);
- return fwnode_handle_get(&c->fwnode);
+
+ for (;;) {
+ if (kobject_get_unless_zero(&c->kobj))
+ return &c->fwnode;
+
+ if (list_is_last(&c->entry, &p->children))
+ break;
+
+ c = list_next_entry(c, entry);
+ }
+
+ return NULL;
}
static struct fwnode_handle *
@@ -529,10 +540,9 @@ software_node_get_named_child_node(const struct fwnode_handle *fwnode,
return NULL;
list_for_each_entry(child, &swnode->children, entry) {
- if (!strcmp(childname, kobject_name(&child->kobj))) {
- swnode_get(child);
+ if (!strcmp(childname, kobject_name(&child->kobj)) &&
+ kobject_get_unless_zero(&child->kobj))
return &child->fwnode;
- }
}
return NULL;
}
--
2.34.1
prev parent reply other threads:[~2026-11-04 15:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 15:43 [PATCH 0/4] software node: fix lookup of swnode in release path Peng Fan (OSS)
2026-11-04 15:43 ` [PATCH 1/4] software node: do not resurrect swnode being released Peng Fan (OSS)
2026-11-04 15:43 ` [PATCH 2/4] software node: use kobject_get_unless_zero() in software_node_find_by_name() Peng Fan (OSS)
2026-11-04 21:29 ` Andy Shevchenko
2026-11-04 15:43 ` [PATCH 3/4] software node: handle missing remote endpoint node Peng Fan (OSS)
2026-11-04 15:43 ` Peng Fan (OSS) [this message]
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=20261104-swnode-race-v1-v1-4-9406a67e25be@nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@kernel.org \
--cc=dakr@kernel.org \
--cc=djrscally@gmail.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=imx@lists.linux.dev \
--cc=johan@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peng.fan@nxp.com \
--cc=rafael.j.wysocki@intel.com \
--cc=rafael@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/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
all inboxes | Powered by JetHome®