public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mfd: core: Delete corresponding OF node entries from list on  MFD removal
@ 2022-08-09  6:03 Michał Oleszczyk
  2022-08-10 11:28 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Michał Oleszczyk @ 2022-08-09  6:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: Lee Jones, Michał Oleszczyk, Michal Oleszczyk

From: Michal Oleszczyk <oleszczyk.m@gmail.com>

When we consider MFD which implements hotplug (e.g. USB hotplug
driver based on product and vendor IDs) functionality it turns out
that its sub-devices are correctly matched with corresponding device
tree nodes only at the first time. When physical device reboots
or is replugged (and MFD driver is disconnected and probed back
again) all sub-devices fails in mfd_add_device() with error
'Failed to locate of_node'.

The reason of that behavior is that when any MFD sub-device is
created for the first time (and matched with device tree node) it
is added to the mfd_of_node_list. It looks like this list is never
cleaned even if devices added there are intentionally removed from
the system. So when MFD device is replugged and all sub-devices
are matched with their device tree nodes again they fail as matched
nodes already exist in mfd_of_node_list. In other words current
implementation does not support MFD with hotplug feature.

This commit extends MFD core for hotplugging support by removing
appropriate OF node entry from mfd_of_node_list when corresponding
device is removed from the system. Thanks to that when device is
added once again it can be matched with its device tree node
successfully.

Signed-off-by: Michal Oleszczyk <oleszczyk.m@gmail.com>
---

Changes in v2: removing unused variable declaration.

 drivers/mfd/mfd-core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 684a011a6396..a9646a03ca8d 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -351,6 +351,7 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
 {
 	struct platform_device *pdev;
 	const struct mfd_cell *cell;
+	struct mfd_of_node_entry *of_entry, *tmp;
 	int *level = data;
 
 	if (dev->type != &mfd_dev_type)
@@ -365,6 +366,12 @@ static int mfd_remove_devices_fn(struct device *dev, void *data)
 	if (cell->swnode)
 		device_remove_software_node(&pdev->dev);
 
+	list_for_each_entry_safe(of_entry, tmp, &mfd_of_node_list, list)
+		if (of_entry->dev == &pdev->dev) {
+			list_del(&of_entry->list);
+			kfree(of_entry);
+		}
+
 	regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
 					       cell->num_parent_supplies);
 
-- 
2.20.1


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

* Re: [PATCH v2] mfd: core: Delete corresponding OF node entries from list on  MFD removal
  2022-08-09  6:03 [PATCH v2] mfd: core: Delete corresponding OF node entries from list on MFD removal Michał Oleszczyk
@ 2022-08-10 11:28 ` Lee Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2022-08-10 11:28 UTC (permalink / raw)
  To: Michał Oleszczyk; +Cc: linux-kernel, Michał Oleszczyk

On Tue, 09 Aug 2022, Michał Oleszczyk wrote:

> From: Michal Oleszczyk <oleszczyk.m@gmail.com>
> 
> When we consider MFD which implements hotplug (e.g. USB hotplug
> driver based on product and vendor IDs) functionality it turns out
> that its sub-devices are correctly matched with corresponding device
> tree nodes only at the first time. When physical device reboots
> or is replugged (and MFD driver is disconnected and probed back
> again) all sub-devices fails in mfd_add_device() with error
> 'Failed to locate of_node'.
> 
> The reason of that behavior is that when any MFD sub-device is
> created for the first time (and matched with device tree node) it
> is added to the mfd_of_node_list. It looks like this list is never
> cleaned even if devices added there are intentionally removed from
> the system. So when MFD device is replugged and all sub-devices
> are matched with their device tree nodes again they fail as matched
> nodes already exist in mfd_of_node_list. In other words current
> implementation does not support MFD with hotplug feature.
> 
> This commit extends MFD core for hotplugging support by removing
> appropriate OF node entry from mfd_of_node_list when corresponding
> device is removed from the system. Thanks to that when device is
> added once again it can be matched with its device tree node
> successfully.
> 
> Signed-off-by: Michal Oleszczyk <oleszczyk.m@gmail.com>
> ---
> 
> Changes in v2: removing unused variable declaration.
> 
>  drivers/mfd/mfd-core.c | 7 +++++++
>  1 file changed, 7 insertions(+)

Applied, thanks.

-- 
Lee Jones [李琼斯]

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

end of thread, other threads:[~2022-08-10 11:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-09  6:03 [PATCH v2] mfd: core: Delete corresponding OF node entries from list on MFD removal Michał Oleszczyk
2022-08-10 11:28 ` Lee Jones

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