All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cesar Cibrian <cesarcibrian.ai@gmail.com>
To: Lee Jones <lee@kernel.org>
Cc: mfd@lists.linux.dev,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Cesar Cibrian <cesarcibrian.ai@gmail.com>
Subject: [PATCH] mfd: core: Remove software node after unregistering platform device
Date: Fri,  4 Dec 2026 10:16:05 -0800	[thread overview]
Message-ID: <20261204181605.22364-1-cesarcibrian.ai@gmail.com> (raw)

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


             reply	other threads:[~2026-12-04 18:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:16 Cesar Cibrian [this message]
2026-12-04 19:47 ` [PATCH] mfd: core: Remove software node after unregistering platform device 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
2026-12-05 11:00           ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204181605.22364-1-cesarcibrian.ai@gmail.com \
    --to=cesarcibrian.ai@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lee@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.