Skip to content

Commit 8a8c942

Browse files
Tzung-Bi ShihBartosz Golaszewski
authored andcommitted
gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()
On error handling paths, gpiolib_cdev_register() doesn't free the allocated resources which results leaks. Fix it. Cc: stable@vger.kernel.org Fixes: 7b9b77a ("gpiolib: add a per-gpio_device line state notification workqueue") Fixes: d83cee3 ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU") Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://lore.kernel.org/r/20260120092650.2305319-1-tzungbi@kernel.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent 70b3c28 commit 8a8c942

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

drivers/gpio/gpiolib-cdev.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,13 +2797,18 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
27972797
return -ENOMEM;
27982798

27992799
ret = cdev_device_add(&gdev->chrdev, &gdev->dev);
2800-
if (ret)
2800+
if (ret) {
2801+
destroy_workqueue(gdev->line_state_wq);
28012802
return ret;
2803+
}
28022804

28032805
guard(srcu)(&gdev->srcu);
28042806
gc = srcu_dereference(gdev->chip, &gdev->srcu);
2805-
if (!gc)
2807+
if (!gc) {
2808+
cdev_device_del(&gdev->chrdev, &gdev->dev);
2809+
destroy_workqueue(gdev->line_state_wq);
28062810
return -ENODEV;
2811+
}
28072812

28082813
gpiochip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
28092814

0 commit comments

Comments
 (0)