]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()
authorTzung-Bi Shih <tzungbi@kernel.org>
Tue, 20 Jan 2026 09:26:50 +0000 (09:26 +0000)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Tue, 20 Jan 2026 09:51:11 +0000 (10:51 +0100)
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>
Link: https://lore.kernel.org/r/20260120092650.2305319-1-tzungbi@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib-cdev.c

index ed249a45d658b985dc179863dc3248ff37ec4597..2adc3c070908225c9ccfe7b90498cea3b3adc9c4 100644 (file)
@@ -2797,13 +2797,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);