On Tue, Apr 28, 2026 at 1:10 PM Andy Shevchenko <[email protected]> wrote: > > On Tue, Apr 28, 2026 at 11:20:26AM +0200, Bartosz Golaszewski wrote: > > If we pass a software node to a newly created device using struct > > platform_device_info, it will not be removed when the device is > > released. This may happen when a module creating the device is removed > > or on failure in platform_device_add(). > > > > When we try to reuse that software node in a subsequent call to > > platform_device_register_full(), it will fails with -EBUSY. Add the > > missing call to device_remove_software_node() in release path. > > > > In addition to the above change, make sure that we still function > > correctly if a software node is used as the primary firmware node as > > well as disallow using two software nodes for platform devices as > > device_add_software_node() does not handle this case correctly (in fact > > a comment inside it states that only one software node per device is > > allowed but it will not bail out if two are used so we need to handle it > > here). > > ... > > > + device_remove_software_node(dev); > > of_node_put(pa->pdev.dev.of_node); > > So, why do we decide not to convert this to fwnode_handle_put() (and > respective > _get() elsewhere)? >
Yes, I'll do it separately, I don't want to shove too much stuff into this bugfix. > ... > > > + /* > > + * Only one software node per device is allowed. Make sure we don't > > + * accept or create two. > > + */ > > + if (pdevinfo->swnode && (pdevinfo->properties || > > is_software_node(pdevinfo->fwnode))) > > return ERR_PTR(-EINVAL); > > ^^^ left for the context. > > ... > > > + /* > > + * If the primary firmware node is a software node and there's no > > + * secondary firmware node, the primary will be affected by the call > > + * to device_remove_software_node() in platform_device_release() and > > + * its reference count will be dropped by one. Take another reference > > + * here to make it have no effect. > > + */ > > + if (is_software_node(pdevinfo->fwnode) && !pdevinfo->swnode) > > + fwnode_handle_get(pdevinfo->fwnode); > > IIUC the `is_software_node(pdevinfo->fwnode) && pdevinfo->swnode` may not > happen here due to the above check. If I haven't missed anything, this check > is simply > Right, it can be a simple is_software_node(pdevinfo->fwnode). Bart

