Linux ACPI
 help / color / mirror / Atom feed
* [PATCH] mfd: core: Remove software node after unregistering platform device
@ 2026-12-04 18:16 Cesar Cibrian
  2026-12-04 19:47 ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Cesar Cibrian @ 2026-12-04 18:16 UTC (permalink / raw)
  To: Lee Jones
  Cc: mfd, Andy Shevchenko, Heikki Krogerus, linux-i2c, linux-acpi,
	linux-kernel, Cesar Cibrian

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 22:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:16 [PATCH] mfd: core: Remove software node after unregistering platform device Cesar Cibrian
2026-12-04 19:47 ` Andy Shevchenko
2026-12-04 20:12   ` Dmitry Torokhov
2026-12-04 20:21     ` Andy Shevchenko
2026-12-04 20:27       ` Dmitry Torokhov
2026-12-04 22:29         ` Julio Cesar Martinez Cibrian
2026-12-04 22:34           ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox