* [PATCH v2] gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()
@ 2026-01-20 9:26 Tzung-Bi Shih
2026-01-20 9:51 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Tzung-Bi Shih @ 2026-01-20 9:26 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij
Cc: tzungbi, linux-gpio, linux-kernel, stable
On error handling paths, gpiolib_cdev_register() doesn't free the
allocated resources which results leaks. Fix it.
Cc: stable@vger.kernel.org
Fixes: 7b9b77a8bba9 ("gpiolib: add a per-gpio_device line state notification workqueue")
Fixes: d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
v2:
- Fix the jumping over guard() issue reported in
https://lore.kernel.org/linux-gpio/202601200022.ZFwz8K6u-lkp@intel.com/T/#u.
- Title prefix: "gpiolib" -> "gpio".
v1: https://lore.kernel.org/all/20260116081036.352286-3-tzungbi@kernel.org/
drivers/gpio/gpiolib-cdev.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 3735c9fe1502..b8b6e1873b51 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -2796,13 +2796,18 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
return -ENOMEM;
ret = cdev_device_add(&gdev->chrdev, &gdev->dev);
- if (ret)
+ if (ret) {
+ destroy_workqueue(gdev->line_state_wq);
return ret;
+ }
guard(srcu)(&gdev->srcu);
gc = srcu_dereference(gdev->chip, &gdev->srcu);
- if (!gc)
+ if (!gc) {
+ cdev_device_del(&gdev->chrdev, &gdev->dev);
+ destroy_workqueue(gdev->line_state_wq);
return -ENODEV;
+ }
gpiochip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
--
2.52.0.457.g6b5491de43-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()
2026-01-20 9:26 [PATCH v2] gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register() Tzung-Bi Shih
@ 2026-01-20 9:51 ` Bartosz Golaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-01-20 9:51 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij, Tzung-Bi Shih
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, stable
On Tue, 20 Jan 2026 09:26:50 +0000, Tzung-Bi Shih wrote:
> On error handling paths, gpiolib_cdev_register() doesn't free the
> allocated resources which results leaks. Fix it.
>
>
Applied, thanks!
[1/1] gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()
commit: 8a8c942cad4cd12f739a8bb60cac77fd173c4e07
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-20 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-20 9:26 [PATCH v2] gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register() Tzung-Bi Shih
2026-01-20 9:51 ` 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®