Re: [PATCH] mfd: core: Remove software node after unregistering platform device

From: Dmitry Torokhov

Date: Fri Dec 04 2026 - 15:12:15 EST


Hi Andy,

On Fri, Dec 04, 2026 at 09:47:14PM +0200, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 10:16:05AM -0800, Cesar Cibrian wrote:
> > mfd_add_device() attaches cell->swnode before calling
> > platform_device_add(), but mfd_remove_devices_fn() calls
> > device_remove_software_node() before platform_device_unregister().
> >
> > If the child driver propagates dev_fwnode() to a sub-device (for
> > example, i2c-designware sharing its fwnode with the i2c_adapter
> > device on Intel LPSS), removing the software node first clears
> > fwnode->secondary while the sub-device is still registered. When
> > platform_device_unregister() subsequently tears down the child,
> > software_node_notify_remove() sees dev_to_swnode() == NULL on the
> > sub-device and skips cleanup, leaking a swnode reference and
> > leaving a stale sysfs symlink that triggers a warning on rebind:
> >
> > sysfs: cannot create duplicate filename '/kernel/software_nodes/node0/i2c-0'
> >
> > Move device_remove_software_node() after platform_device_unregister()
> > (device_for_each_child_reverse() holds a reference on dev throughout
> > mfd_remove_devices_fn()). Because acpi_unbind_one() calls
> > set_primary_fwnode(dev, NULL), which skips clearing fn->secondary
> > when fn == dev->parent->fwnode, also clear the parent's secondary
> > fwnode when the child shared its parent's fwnode so rebinding does
> > not fail with -EBUSY.
>
> I believe it's a local hack against bigger issue which is discussed here
> https://lore.kernel.org/lkml/20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@xxxxxxxxx/
>
> I Cc'ed people from that thread. Meanwhile, can you test the proposed series
> and confirm if it fixes your issue or not?

My series will not fix this on its own. We still need to reorder
software node removal so it stays intact while child devices are being
torn down.

What my series does fix is the shared_fwnode/set_secondary_fwnode()
workaround in this patch. Once device_del() unbinds the driver first and
tears down i2c_adapter while the secondary link is intact,
set_primary_fwnode(&pdev->dev, NULL) sees that pdev->dev attached the
secondary node, moves it onto pdev->dev.fwnode, and clears fn->secondary
automatically.

Also, on non-ACPI shared primary nodes where acpi_unbind_one() does not
run, clearing dev->parent's secondary fwnode before calling
device_remove_software_node(&pdev->dev) makes dev_to_swnode(&pdev->dev)
return NULL and actually leaks cell->swnode's reference.

Thanks.

--
Dmitry