Re: [PATCH v2 5/8] driver core: platform: warn on bad fwnode assignment
From: Johan Hovold
Date: Tue Nov 10 2026 - 06:00:50 EST
On Tue, Nov 10, 2026 at 09:51:21AM +0100, Johan Hovold wrote:
> Commit e6054f410c97 ("driver core: platform: amend the API contract for
> fwnode setters") added a warning to platform_device_set_fwnode() in case
> the current firmware node pointer points to a software node as that may
> prevent software_node_notify_remove() from being called.
>
> This is only an issue if the platform device has been registered however
> as software_node_notify() is only called for registered devices. A
> bigger issue is that a secondary firmware node assigned before the call
> may be silently lost (and leaked in case of software nodes) as these
> helpers do not use set_primary_fwnode().
>
> Replace the current software node check with a warning in case the
> device already has a primary or secondary firmware node assigned to
> catch any (hard-to-debug) issues due to a secondary node being assigned
> before the call.
>
> Note that this also avoids making claims about the device firmware node
> pointing to the primary firmware node, which is not the case when the
> device only has a secondary node.
>
> Fixes: e6054f410c97 ("driver core: platform: amend the API contract for fwnode setters")
> Cc: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
> Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
> ---
> drivers/base/platform.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
> void platform_device_set_fwnode(struct platform_device *pdev,
> struct fwnode_handle *fwnode)
> {
> /*
> - * If we call this function for a platform device whose primary
> - * firmware node is a software node, we'll never end up calling the
> - * symmetric software_node_notify_remove(). There are no users for this
> - * right now in the tree so just disallow it.
> + * A secondary firmware node may be lost as set_primary_fwnode() is
> + * not used here, warn for now if a node has already been set.
> */
> - WARN_ON(is_software_node(dev_fwnode(&pdev->dev)));
> + WARN_ON(dev_fwnode(&pdev->dev));
Sashiko points out that this may trigger a warning on probe deferral in
an ASoC driver due to a new user of platform_device_set_of_node()
currently in linux-next.
Will revisit.
Johan