Skip to contentSkip to conversation

gpio: cdev: fix a NULL-pointer dereference with DEBUG enabled

PATCH In review Bartosz Golaszewski 2 participants 3 messages Feb 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: cdev: fix a NULL-pointer dereference with DEBUG enabled

From: Bartosz Golaszewski <[email protected]>

We are actually passing the gc pointer to chip_dbg() so we have to srcu_dereference() it.

Fixes 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
---
 drivers/gpio/gpiolib-cdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-cdev.c +2 -2
index 85037fa4925e..f384fa278764 100644
@@ -2795,8 +2795,8 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
 		return ret;
 
 	guard(srcu)(&gdev->srcu);
-
-	if (!rcu_access_pointer(gdev->chip))
+	gc = srcu_dereference(gdev->chip, &gdev->srcu);
+	if (!gc)
 		return -ENODEV;
 
 	chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
Signature · 1 line
2.40.1
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

We are actually passing the gc pointer to chip_dbg() so we have to srcu_dereference() it.

Fixes 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
Quoted 9 lines
---
  drivers/gpio/gpiolib-cdev.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-cdev.c +0 -0
index 85037fa4925e..f384fa278764 100644

drivers/gpio/gpiolib-cdev.c int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) · line 2802

Quoted 10 lines
drivers/gpio/gpiolib-cdev.c +2 -2
@@ -2795,8 +2795,8 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
  		return ret;
 
  	guard(srcu)(&gdev->srcu);
-
-	if (!rcu_access_pointer(gdev->chip))
+	gc = srcu_dereference(gdev->chip, &gdev->srcu);
+	if (!gc)
  		return -ENODEV;
 
  	chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#2 lore raw
Quoted 4 lines · Marek Szyprowski
Quoted 2 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 7 lines

We are actually passing the gc pointer to chip_dbg() so we have to srcu_dereference() it.

Fixes 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")

Thanks, patch applied.

Bart

[snip]