[PATCH 1/6] spi: fix NULL pointer dereference for board info devices

Ahmad Fatoum a.fatoum at barebox.org
Thu Nov 19 10:58:11 PST 2026


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




More information about the barebox mailing list