[PATCH 6.12.y 0/3] gpiolib: backport 16fdabe143fc

From: Quentin Schulz

Date: Thu Jun 18 2026 - 12:11:09 EST


Backport 16fdabe143fc ("gpio: Fix resource leaks on errors in
gpiochip_add_data_with_key()") to 6.12.y. To make the git diff more
similar with the upstream commit, also backport 375790f18396 ("gpiolib:
Extract gpiochip_choose_fwnode() for wider use") and 550300b9a295
("gpiolib: Remove redundant assignment of return variable").

The changes between 16fdabe143fc and the third patch of this series is
(according to git-range-diff):

"""
## drivers/gpio/gpiolib.c ##
@@ drivers/gpio/gpiolib.c: static const struct device_type gpio_dev_type = {
@@ drivers/gpio/gpiolib.c: int gpiochip_add_data_with_key(struct gpio_chip *gc, voi
+ }
+
+ gdev->can_sleep = gc->can_sleep;
-+ rwlock_init(&gdev->line_state_lock);
-+ RAW_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
++ BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
+ BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier);
+#ifdef CONFIG_PINCTRL
+ INIT_LIST_HEAD(&gdev->pin_ranges);
@@ drivers/gpio/gpiolib.c: int gpiochip_add_data_with_key(struct gpio_chip *gc, voi
- gdev->ngpio = gc->ngpio;
- gdev->can_sleep = gc->can_sleep;
-
-- rwlock_init(&gdev->line_state_lock);
-- RAW_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
+- BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
- BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier);
-
- ret = init_srcu_struct(&gdev->srcu);
@@ drivers/gpio/gpiolib.c: int gpiochip_add_data_with_key(struct gpio_chip *gc, voi
@@ drivers/gpio/gpiolib.c: int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
ret = gpiodev_add_to_list_unlocked(gdev);
if (ret) {
- gpiochip_err(gc, "GPIO integer space overlap, cannot add chip\n");
+ chip_err(gc, "GPIO integer space overlap, cannot add chip\n");
- goto err_cleanup_desc_srcu;
+ goto err_put_device;
}
"""

s/gpiochip_err/chip_err/ aside, the rest of the diff comes from feature
commits which do not fit the rules for backporting to stable.

Signed-off-by: Quentin Schulz <quentin.schulz@xxxxxxxxx>
---
Andy Shevchenko (2):
gpiolib: Extract gpiochip_choose_fwnode() for wider use
gpiolib: Remove redundant assignment of return variable

Tzung-Bi Shih (1):
gpio: Fix resource leaks on errors in gpiochip_add_data_with_key()

drivers/gpio/gpiolib.c | 156 +++++++++++++++++++++++++------------------------
1 file changed, 79 insertions(+), 77 deletions(-)
---
base-commit: 1d3a00d3bacff25652c96e1527610c69e91f7c38
change-id: 20260618-6-12-cve-2026-31732-63076d516720

Best regards,
--
Quentin Schulz <quentin.schulz@xxxxxxxxx>