Skip to content

Commit ab140fc

Browse files
Tzung-Bi Shihgregkh
authored andcommitted
gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()
commit 8a8c942 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1641434 commit ab140fc

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
@@ -2821,13 +2821,18 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
28212821
return -ENOMEM;
28222822

28232823
ret = cdev_device_add(&gdev->chrdev, &gdev->dev);
2824-
if (ret)
2824+
if (ret) {
2825+
destroy_workqueue(gdev->line_state_wq);
28252826
return ret;
2827+
}
28262828

28272829
guard(srcu)(&gdev->srcu);
28282830
gc = srcu_dereference(gdev->chip, &gdev->srcu);
2829-
if (!gc)
2831+
if (!gc) {
2832+
cdev_device_del(&gdev->chrdev, &gdev->dev);
2833+
destroy_workqueue(gdev->line_state_wq);
28302834
return -ENODEV;
2835+
}
28312836

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

0 commit comments

Comments
 (0)