Skip to contentSkip to conversation

gpio: cdev: Fix resource leaks on errors in gpiolib_cdev_register()

PATCH Applied Tzung-Bi Shih 2 participants 2 messages Jan 20

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

PATCH v2 1/1 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.

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")

---
v2:
- Fix the jumping over guard() issue reported in
https://lore.kernel.org/linux-gpio/[email protected]/T/#u.
- Title prefix: "gpiolib" -> "gpio".

v1: https://lore.kernel.org/all/[email protected]/

 drivers/gpio/gpiolib-cdev.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-cdev.c +7 -2
index 3735c9fe1502..b8b6e1873b51 100644
@@ -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);
 
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#1 lore raw
Quoted 4 lines · Tzung-Bi Shih

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,

Signature · 1 line
Bartosz Golaszewski <[email protected]>