* [PATCH] spi: bcm2835: fix device_node reference leak in bcm2835_spi_setup()
@ 2026-09-23 18:44 Lucas Costa
2026-09-24 7:48 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Lucas Costa @ 2026-09-23 18:44 UTC (permalink / raw)
To: Mark Brown, Florian Fainelli, Ray Jui, Scott Branden
Cc: Bartosz Golaszewski, bcm-kernel-feedback-list, linux-spi,
linux-rpi-kernel, linux-arm-kernel, linux-kernel, Lucas Costa,
stable
of_find_compatible_node() returns a device_node with its reference count
incremented, but the function bcm2835_spi_setup() uses the ret value
in the loop to check a condition and never releases it.
Store the returned node and drop it with of_node_put() before breaking
out of the loop.
Fixes: e19c1272c80a ("spi: bcm2835: Restore native CS probing when pinctrl-bcm2835 is absent")
Cc: stable@vger.kernel.org
Signed-off-by: Lucas Costa <2000.costalucas@gmail.com>
---
drivers/spi/spi-bcm2835.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index 8f8715809c7c..8909757c94e3 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -1226,6 +1226,7 @@ static int bcm2835_spi_setup(struct spi_device *spi)
struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
struct bcm2835_spidev *target = spi_get_ctldata(spi);
struct gpiod_lookup_table *lookup __free(kfree) = NULL;
+ struct device_node *np;
static const char * const pinctrl_compats[] = {
"brcm,bcm2835-gpio",
"brcm,bcm2711-gpio",
@@ -1297,8 +1298,11 @@ 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]))
+ np = of_find_compatible_node(NULL, NULL, pinctrl_compats[i]);
+ if (np) {
+ of_node_put(np);
break;
+ }
}
if (i == ARRAY_SIZE(pinctrl_compats))
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] spi: bcm2835: fix device_node reference leak in bcm2835_spi_setup()
2026-09-23 18:44 [PATCH] spi: bcm2835: fix device_node reference leak in bcm2835_spi_setup() Lucas Costa
@ 2026-09-24 7:48 ` Bartosz Golaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-09-24 7:48 UTC (permalink / raw)
To: Lucas Costa
Cc: Bartosz Golaszewski, bcm-kernel-feedback-list, linux-spi,
linux-rpi-kernel, linux-arm-kernel, linux-kernel, stable,
Mark Brown, Florian Fainelli, Ray Jui, Scott Branden
On Wed, 23 Sep 2026 20:44:50 +0200, Lucas Costa
<2000.costalucas@gmail.com> said:
> of_find_compatible_node() returns a device_node with its reference count
> incremented, but the function bcm2835_spi_setup() uses the ret value
> in the loop to check a condition and never releases it.
>
> Store the returned node and drop it with of_node_put() before breaking
> out of the loop.
>
> Fixes: e19c1272c80a ("spi: bcm2835: Restore native CS probing when pinctrl-bcm2835 is absent")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lucas Costa <2000.costalucas@gmail.com>
> ---
> drivers/spi/spi-bcm2835.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
> index 8f8715809c7c..8909757c94e3 100644
> --- a/drivers/spi/spi-bcm2835.c
> +++ b/drivers/spi/spi-bcm2835.c
> @@ -1226,6 +1226,7 @@ static int bcm2835_spi_setup(struct spi_device *spi)
> struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
> struct bcm2835_spidev *target = spi_get_ctldata(spi);
> struct gpiod_lookup_table *lookup __free(kfree) = NULL;
> + struct device_node *np;
> static const char * const pinctrl_compats[] = {
> "brcm,bcm2835-gpio",
> "brcm,bcm2711-gpio",
> @@ -1297,8 +1298,11 @@ 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]))
> + np = of_find_compatible_node(NULL, NULL, pinctrl_compats[i]);
> + if (np) {
> + of_node_put(np);
> break;
> + }
> }
>
> if (i == ARRAY_SIZE(pinctrl_compats))
> --
> 2.43.0
>
>
Just use cleanup.h like so:
struct device_node *np __free(device_node) = of_find_compatible_node(...);
It's a oneliner this way.
Bart
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-24 7:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-23 18:44 [PATCH] spi: bcm2835: fix device_node reference leak in bcm2835_spi_setup() Lucas Costa
2026-09-24 7:48 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®