Skip to contentSkip to conversation

FAILED: patch "[PATCH] gpio: cdev: Fix resource leaks on errors in" failed to apply to 6.12-stable tree

PATCH [email protected] 1 participant 1 message Jan 27

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 8a8c942cad4cd12f739a8bb60cac77fd173c4e07
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026012718-antacid-populace-6683@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 8a8c942cad4cd12f739a8bb60cac77fd173c4e07 Mon Sep 17 00:00:00 2001
From: Tzung-Bi Shih <[email protected]>
Date: Tue, 20 Jan 2026 09:26:50 +0000
Subject: [PATCH] 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")
drivers/gpio/gpiolib-cdev.c +7 -2
index ed249a45d658..2adc3c070908 100644
@@ -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);