mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] spi: fix NULL pointer dereference for board info devices
@ 2026-11-19 18:58 Ahmad Fatoum
  2026-11-19 18:58 ` [PATCH 2/6] driver: pass the requested node to the rescan hook Ahmad Fatoum
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2026-11-19 18:58 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan, Ahmad Fatoum

Devices registered with spi_register_board_info() have no device node,
but spi_new_device() unconditionally stores the new device in it.

The at91sam9m10g45ek board, which has the Atmel SPI driver enabled in
its defconfig, still registers its devices this way. Let's add an
of_node_set_dev() helper that only sets the node's device if there is
a node and use it here.

Fixes: cd23b6facf33 ("common: add initial barebox deep-probe support")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/spi/spi.c | 2 +-
 include/of.h      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b64e20664985..53bcd22b8c56 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -125,7 +125,7 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
 	if (status)
 		goto fail;
 
-	chip->device_node->dev = &proxy->dev;
+	of_node_set_dev(chip->device_node, &proxy->dev);
 
 	return proxy;
 fail:
diff --git a/include/of.h b/include/of.h
index 07d435f91475..993315247bf0 100644
--- a/include/of.h
+++ b/include/of.h
@@ -134,6 +134,12 @@ static inline struct device_node *of_node_get(struct device_node *node)
 static inline void of_node_put(struct device_node *node) { }
 DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))
 
+static inline void of_node_set_dev(struct device_node *np, struct device *dev)
+{
+	if (np)
+		np->dev = dev;
+}
+
 void of_print_property(const void *data, int len);
 void of_print_cmdline(struct device_node *root);
 
-- 
2.47.3




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

end of thread, other threads:[~2026-11-20 12:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 6/6] spi: allow creating siblings on demand while populating the bus Ahmad Fatoum

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