mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>,
	Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/6] driver: pass the requested node to the rescan hook
Date: Thu, 19 Nov 2026 19:58:12 +0100	[thread overview]
Message-ID: <20261119185828.92337-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261119185828.92337-1-a.fatoum@barebox.org>

of_device_create_on_demand() rescans the parent device, so a bus like
I2C or SPI registers the device for the requested node. The hooks
register every child that has no device yet though, not only the one
asked for.

Let's pass the node along, so the hooks can restrict themselves to it.
NULL still means all children. The I2C and SPI hooks ignore the node
for now, so there is no functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/i2c/i2c.c     | 2 +-
 drivers/of/platform.c | 4 ++--
 drivers/spi/spi.c     | 2 +-
 include/device.h      | 5 +++--
 include/driver.h      | 4 ++--
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 407c4db8a76a..cfc340736309 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -485,7 +485,7 @@ int of_i2c_register_devices_by_node(struct device_node *node)
 	return 0;
 }
 
-static void i2c_hw_rescan(struct device *dev)
+static void i2c_hw_rescan(struct device *dev, struct device_node *np)
 {
 	struct i2c_adapter *adap;
 
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 0346d87a2b61..12a1b759fc07 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -138,7 +138,7 @@ struct device *of_platform_device_create(struct device_node *np,
 	 * devices.
 	 */
 	if (np->dev) {
-		device_rescan(np->dev);
+		device_rescan(np->dev, NULL);
 		return np->dev;
 	}
 
@@ -450,7 +450,7 @@ static struct device *of_device_create_on_demand(struct device_node *np)
 		return NULL;
 
 	if (!np->dev && parent->dev)
-		device_rescan(parent->dev);
+		device_rescan(parent->dev, np);
 
 	/* Create all parent devices needed for the requested device */
 	parent_dev = parent->dev ? : of_device_create_on_demand(parent);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 53bcd22b8c56..b1806a2ea445 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -199,7 +199,7 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
 	}
 }
 
-static void spi_controller_rescan(struct device *dev)
+static void spi_controller_rescan(struct device *dev, struct device_node *np)
 {
 	struct spi_controller *ctrl;
 
diff --git a/include/device.h b/include/device.h
index 7abeed9c460f..34b45a9bb014 100644
--- a/include/device.h
+++ b/include/device.h
@@ -59,7 +59,8 @@ struct of_device_id;
  * @dma_offset: DMA offset.
  * @detect: For devices which take longer to probe, this is called when the driver
  *          should actually detect client devices.
- * @rescan: Callback to rescan the device.
+ * @rescan: Callback to rescan the device. If @np is not NULL, only the
+ *          device for that child node needs to be created.
  * @deferred_probe_reason: If a driver probe is deferred, this stores the last error.
  */
 struct device {
@@ -119,7 +120,7 @@ struct device {
 #endif
 
 	int (*detect)(struct device *);
-	void (*rescan)(struct device *);
+	void (*rescan)(struct device *dev, struct device_node *np);
 
 	char *deferred_probe_reason;
 };
diff --git a/include/driver.h b/include/driver.h
index a93da2e06f62..ec1f1ccfb85e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -98,10 +98,10 @@ static inline void put_device(struct device *dev) {}
 void free_device_res(struct device *dev);
 void free_device(struct device *dev);
 
-static inline void device_rescan(struct device *dev)
+static inline void device_rescan(struct device *dev, struct device_node *np)
 {
 	if (dev->rescan)
-		dev->rescan(dev);
+		dev->rescan(dev, np);
 }
 
 /* Iterate over a devices children
-- 
2.47.3




  reply	other threads:[~2026-11-19 19:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 18:58 [PATCH 1/6] spi: fix NULL pointer dereference for board info devices Ahmad Fatoum
2026-11-19 18:58 ` Ahmad Fatoum [this message]
2026-11-19 18:58 ` [PATCH 3/6] i2c: factor out of_i2c_register_device() Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 4/6] i2c: allow creating siblings on demand while populating the bus Ahmad Fatoum
2026-11-20 11:04   ` Alexander Shiyan
2026-11-19 18:58 ` [PATCH 5/6] spi: factor out spi_of_register_slave() Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 6/6] spi: allow creating siblings on demand while populating the bus Ahmad Fatoum

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=20261119185828.92337-2-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=eagle.alexander923@gmail.com \
    /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