[PATCH 1/8] driver: don't clear unrelated struct device_node::device on unregister

Ahmad Fatoum a.fatoum at pengutronix.de
Sun Nov 26 22:35:52 PST 2023


Device nodes have a pointer to the device that was instantiated for it.
In some cases, we have both a platform device and a virtual device as
child instantiated from it with both pointing at the same device node.

So far, when unregistering the virtual device, we would clear the device
member, even if it happens to point at another device. Fix this by only
clearing it if the device it points at is the one that's actually is
being removed.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/base/driver.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 02d8fb0b6f2a..93607fc3b09d 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -273,6 +273,7 @@ int unregister_device(struct device *old_dev)
 	struct device_alias *alias, *at;
 	struct cdev *cdev, *ct;
 	struct device *child, *dt;
+	struct device_node *np;
 
 	dev_dbg(old_dev, "unregister\n");
 
@@ -305,8 +306,10 @@ int unregister_device(struct device *old_dev)
 	/* remove device from parents child list */
 	if (old_dev->parent)
 		list_del(&old_dev->sibling);
-	if (dev_of_node(old_dev))
-		old_dev->of_node->dev = NULL;
+
+	np = dev_of_node(old_dev);
+	if (np && np->dev == old_dev)
+		np->dev = NULL;
 
 	return 0;
 }
-- 
2.39.2




More information about the barebox mailing list