mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/8] driver: don't clear unrelated struct device_node::device on unregister
Date: Mon, 27 Nov 2023 07:35:52 +0100	[thread overview]
Message-ID: <20231127063559.2205776-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231127063559.2205776-1-a.fatoum@pengutronix.de>

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@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




  reply	other threads:[~2023-11-27  6:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27  6:35 [PATCH 0/8] optee: add bidirectional communication support Ahmad Fatoum
2023-11-27  6:35 ` Ahmad Fatoum [this message]
2023-11-27  6:35 ` [PATCH 2/8] deep-probe: don't panic when device can't be created Ahmad Fatoum
2023-11-27  6:35 ` [PATCH 3/8] deep-probe: skip on-demand platform dev creation for nodes without compatible Ahmad Fatoum
2023-11-29  9:12   ` Sascha Hauer
2023-11-30  8:02     ` Ahmad Fatoum
2023-11-27  6:35 ` [PATCH 4/8] devinfo: indicate if device tree nodes are differently populated Ahmad Fatoum
2023-11-27  6:35 ` [PATCH 5/8] include: uaccess.h: import from linux Ahmad Fatoum
2023-11-27  6:35 ` [PATCH 6/8] optee: add bidirectional communication support Ahmad Fatoum
2023-11-27  6:35 ` [PATCH 7/8] optee: add experimental support for /dev/tee0 Ahmad Fatoum
2023-11-27  6:35 ` [PATCH 8/8] hw_random: add implementation for OP-TEE RNG pseudo TA Ahmad Fatoum
2023-12-01 10:39 ` [PATCH 0/8] optee: add bidirectional communication support Sascha Hauer

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=20231127063559.2205776-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox