From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
Cc: 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>,
"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: Re: [PATCH v2 3/4] software node: pin referenced swnodes while resolving them
Date: Mon, 9 Nov 2026 23:13:35 +0200 [thread overview]
Message-ID: <avI3f7ZK_qx_Rd7j@ashevche-desk.local> (raw)
In-Reply-To: <20261106-swnode-race-v1-v2-3-f8bc7b14d578@nxp.com>
On Fri, Nov 06, 2026 at 12:38:37PM +0800, Peng Fan (OSS) wrote:
> software_node_get_reference_args() and software_node_add_links() resolve
> DEV_PROP_REF entries by calling software_node_fwnode(), which returns a
> borrowed pointer. The referenced swnode can be unregistered and released
> between the lookup and the fwnode reference or link operation.
>
> Use software_node_to_swnode_get() for software node references and keep
> the reference until the argument or link has been set up. For direct
> fwnode references in software_node_add_links(), take a reference with
> fwnode_handle_get() and release it after fwnode_link_add() completes.
...
> - if (ref->swnode)
> - refnode = software_node_fwnode(ref->swnode);
> - else if (ref->fwnode)
> - refnode = ref->fwnode;
> - else
> - return -EINVAL;
> + if (ref->swnode) {
> + struct swnode *remote = software_node_to_swnode_get(ref->swnode);
>
> - if (!refnode)
> - return -ENOTCONN;
> + if (!remote)
> + return -ENOTCONN;
It's always better to maintain when assignment is coupled with a validation
check.
struct swnode *remote;
remote = software_node_to_swnode_get(ref->swnode);
if (!remote)
return -ENOTCONN;
> + refnode = &remote->fwnode;
> + } else if (ref->fwnode) {
> + refnode = fwnode_handle_get(ref->fwnode);
> + } else {
> + return -EINVAL;
> + }
...
> - if (ref->swnode)
> - refnode = software_node_fwnode(ref->swnode);
> - else if (ref->fwnode)
> - refnode = ref->fwnode;
> - else
> + if (ref->swnode) {
> + struct swnode *remote;
> + remote = software_node_to_swnode_get(ref->swnode);
> + if (!remote)
> + continue;
Seems like a dup code, perhaps a helper?
> + refnode = &remote->fwnode;
> + } else if (ref->fwnode) {
> + refnode = fwnode_handle_get(ref->fwnode);
> + } else {
> continue;
> + }
>
> /* Supplier not registered yet, or self-reference. */
> - if (!refnode || refnode == &swnode->fwnode)
> + if (refnode == &swnode->fwnode) {
> + fwnode_handle_put(refnode);
> continue;
> + }
>
> fwnode_link_add(&swnode->fwnode, refnode, 0);
> + fwnode_handle_put(refnode);
I don't see a context, but it looks like it continues in both cases.
If so, the above may be refactored for that.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-09 21:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 4:38 [PATCH v2 0/4] software node: fix lookup of swnode in release path Peng Fan (OSS)
2026-11-06 4:38 ` [PATCH v2 1/4] software node: do not resurrect swnode being released Peng Fan (OSS)
2026-11-06 8:57 ` Peng Fan
2026-11-06 4:38 ` [PATCH v2 2/4] software node: use kobject_get_unless_zero() in software_node_find_by_name() Peng Fan (OSS)
2026-11-06 4:38 ` [PATCH v2 3/4] software node: pin referenced swnodes while resolving them Peng Fan (OSS)
2026-11-09 21:13 ` Andy Shevchenko [this message]
2026-11-06 4:38 ` [PATCH v2 4/4] software node: pin remote endpoint swnode Peng Fan (OSS)
2026-11-09 21:14 ` Andy Shevchenko
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=avI3f7ZK_qx_Rd7j@ashevche-desk.local \
--to=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=peng.fan@oss.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®