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 6/6] spi: allow creating siblings on demand while populating the bus
Date: Thu, 19 Nov 2026 19:58:16 +0100	[thread overview]
Message-ID: <20261119185828.92337-6-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261119185828.92337-1-a.fatoum@barebox.org>

SPI orders things like I2C: the rescan hook is installed only after the
controller registered its devices, and a device's node only gets its
device after probe. A device that needs a later sibling while probing
thus gets that sibling created as a platform device instead of an SPI
device.

Fix it the same way as for I2C, including that the nested rescan only
registers the requested node.

Fixes: 2366fa3a808e ("spi: implement rescan")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/spi/spi.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 850ea2c7b62f..15b654b750db 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -121,12 +121,15 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
 	if (status)
 		goto fail;
 
-	status = register_device(&proxy->dev);
-	if (status)
-		goto fail;
-
+	/* claim the node before probe can rescan the bus */
 	of_node_set_dev(chip->device_node, &proxy->dev);
 
+	status = register_device(&proxy->dev);
+	if (status) {
+		of_node_set_dev(chip->device_node, NULL);
+		goto fail;
+	}
+
 	return proxy;
 fail:
 	free(proxy);
@@ -211,7 +214,12 @@ static void spi_controller_rescan(struct device *dev, struct device_node *np)
 	list_for_each_entry(ctrl, &spi_controller_list, list) {
 		if (ctrl->dev != dev)
 			continue;
-		spi_of_register_slaves(ctrl);
+
+		if (!np)
+			spi_of_register_slaves(ctrl);
+		else if (np->parent == ctrl->dev->of_node &&
+			 of_device_is_available(np))
+			spi_of_register_slave(ctrl, np);
 	}
 }
 
@@ -579,16 +587,16 @@ int spi_register_controller(struct spi_controller *ctrl)
 
 	list_add_tail(&ctrl->list, &spi_controller_list);
 
+	/* children probed below may need their siblings created on demand */
+	if (!ctrl->dev->rescan)
+		ctrl->dev->rescan = spi_controller_rescan;
+
 	spi_of_register_slaves(ctrl);
 
 	/* populate children from any spi device tables */
 	scan_boardinfo(ctrl);
-	status = 0;
 
-	if (!ctrl->dev->rescan)
-		ctrl->dev->rescan = spi_controller_rescan;
-
-	return status;
+	return 0;
 }
 EXPORT_SYMBOL(spi_register_controller);
 
-- 
2.47.3




      parent reply	other threads:[~2026-11-19 18:59 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 ` [PATCH 2/6] driver: pass the requested node to the rescan hook Ahmad Fatoum
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 ` Ahmad Fatoum [this message]

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