Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] gpio: shared: fix a NULL-pointer dereference
@ 2025-11-18 20:04 Bartosz Golaszewski
  2025-11-18 20:08 ` Mark Brown
  2025-11-19  7:32 ` Bartosz Golaszewski
  0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2025-11-18 20:04 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

The fact that CONFIG_OF is enabled does not mean that the device tree is
populated and that of_root points to a valid device node. Check if it's
NULL before trying to traverse the tree.

Fixes: a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/all/dbe20642-9662-40af-a593-c1263baea73b@sirena.org.uk/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib-shared.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index c22eaf05eef23..4ce574a21850b 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -205,7 +205,10 @@ static int gpio_shared_of_traverse(struct device_node *curr)
 
 static int gpio_shared_of_scan(void)
 {
-	return gpio_shared_of_traverse(of_root);
+	if (of_root)
+		return gpio_shared_of_traverse(of_root);
+
+	return 0;
 }
 #else
 static int gpio_shared_of_scan(void)
-- 
2.51.0


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

* Re: [PATCH] gpio: shared: fix a NULL-pointer dereference
  2025-11-18 20:04 [PATCH] gpio: shared: fix a NULL-pointer dereference Bartosz Golaszewski
@ 2025-11-18 20:08 ` Mark Brown
  2025-11-19  7:32 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2025-11-18 20:08 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski

[-- Attachment #1: Type: text/plain, Size: 377 bytes --]

On Tue, Nov 18, 2025 at 09:04:59PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> The fact that CONFIG_OF is enabled does not mean that the device tree is
> populated and that of_root points to a valid device node. Check if it's
> NULL before trying to traverse the tree.

Tested-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] gpio: shared: fix a NULL-pointer dereference
  2025-11-18 20:04 [PATCH] gpio: shared: fix a NULL-pointer dereference Bartosz Golaszewski
  2025-11-18 20:08 ` Mark Brown
@ 2025-11-19  7:32 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2025-11-19  7:32 UTC (permalink / raw)
  To: Mark Brown, Bartosz Golaszewski
  Cc: Bartosz Golaszewski, Linus Walleij, linux-gpio, linux-kernel

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Tue, 18 Nov 2025 21:04:59 +0100, Bartosz Golaszewski wrote:
> The fact that CONFIG_OF is enabled does not mean that the device tree is
> populated and that of_root points to a valid device node. Check if it's
> NULL before trying to traverse the tree.
> 
> 

Applied, thanks!

[1/1] gpio: shared: fix a NULL-pointer dereference
      https://git.kernel.org/brgl/linux/c/01be9047988d15850ca15d146c5f4aeb5de2f569

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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

end of thread, other threads:[~2025-11-19  7:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18 20:04 [PATCH] gpio: shared: fix a NULL-pointer dereference Bartosz Golaszewski
2025-11-18 20:08 ` Mark Brown
2025-11-19  7:32 ` Bartosz Golaszewski

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