[PATCH v2] spi: bcm2835: fix device_node reference leak in bcm2835_spi_setup()

Lucas Costa 2000.costalucas at gmail.com
Fri Sep 25 12:30:08 PDT 2026


of_find_compatible_node() returns a device_node with its reference count
incremented, but bcm2835_spi_setup() only uses the return value to test
for a matching node in the loop and never releases it.

Declare the node with a scope-based __free(device_node) cleanup so the
reference is dropped automatically when leaving the loop body, matching
the existing __free(kfree) usage in the same function.

Fixes: e19c1272c80a ("spi: bcm2835: Restore native CS probing when pinctrl-bcm2835 is absent")
Cc: stable at vger.kernel.org
Signed-off-by: Lucas Costa <2000.costalucas at gmail.com>
---
Changes in v2:
- Use a scope-based __free(device_node) cleanup instead of an explicit
  of_node_put(), as suggested by the reviewer.
- v1: https://lore.kernel.org/all/20260923184450.135601-1-2000.costalucas@gmail.com/

 drivers/spi/spi-bcm2835.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index 8f8715809c7c..23606967f7d1 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -1297,7 +1297,9 @@ static int bcm2835_spi_setup(struct spi_device *spi)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(pinctrl_compats); i++) {
-		if (of_find_compatible_node(NULL, NULL, pinctrl_compats[i]))
+		struct device_node *np __free(device_node) =
+			of_find_compatible_node(NULL, NULL, pinctrl_compats[i]);
+		if (np)
 			break;
 	}
 

base-commit: fe2ec83746e501645709761605c2464a44fd2929
-- 
2.43.0




More information about the linux-arm-kernel mailing list