[PATCH] mfd: core: Remove software node after unregistering platform device
From: Cesar Cibrian
Date: Fri Dec 04 2026 - 13:16:28 EST
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.
Fixes: 42e59982917a ("mfd: core: Add support for software nodes")
Signed-off-by: Cesar Cibrian <cesarcibrian.ai@xxxxxxxxx>
---
drivers/mfd/mfd-core.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 16ad4fd26..aa479c2ea 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -358,6 +358,7 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
const struct mfd_cell *cell;
struct mfd_of_node_entry *of_entry, *tmp;
int *level = data;
+ bool shared_fwnode;
if (dev->type != &mfd_dev_type)
return 0;
@@ -368,9 +369,6 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
if (level && cell->level > *level)
return 0;
- if (cell->swnode)
- device_remove_software_node(&pdev->dev);
-
scoped_guard(mutex, &mfd_of_node_mutex) {
list_for_each_entry_safe(of_entry, tmp, &mfd_of_node_list, list)
if (of_entry->dev == &pdev->dev) {
@@ -382,7 +380,17 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
cell->num_parent_supplies);
+ shared_fwnode = dev->parent && dev_fwnode(dev) &&
+ dev_fwnode(dev) == dev_fwnode(dev->parent);
+
platform_device_unregister(pdev);
+
+ if (cell->swnode) {
+ if (shared_fwnode)
+ set_secondary_fwnode(dev->parent, NULL);
+ device_remove_software_node(&pdev->dev);
+ }
+
return 0;
}
--
2.56.1