[PATCH v3 5/5] gpiolib: of: use __free(device_node) in of_get_named_gpiod_flags()

From: Dmitry Torokhov

Date: Thu Oct 22 2026 - 17:58:32 EST


Manage the gpiospec.np device node reference in
of_get_named_gpiod_flags() using __free(device_node) so that error paths
can return directly and the out label can be dropped.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/gpio/gpiolib-of.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index e741a4f218f4..25b97109f97e 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -430,17 +430,17 @@ static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np,
return ERR_PTR(ret);
}

+ struct device_node *chip_np __free(device_node) = gpiospec.np;
+
struct gpio_device *gdev __free(gpio_device_put) =
of_find_gpio_device_by_xlate(&gpiospec);
- if (!gdev) {
- desc = ERR_PTR(-EPROBE_DEFER);
- goto out;
- }
+ if (!gdev)
+ return ERR_PTR(-EPROBE_DEFER);

desc = of_xlate_and_get_gpiod_flags(gpio_device_get_chip(gdev),
&gpiospec, flags);
if (IS_ERR(desc))
- goto out;
+ return desc;

if (flags)
of_gpio_flags_quirks(np, propname, flags, index);
@@ -449,9 +449,6 @@ static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np,
__func__, propname, np, index,
PTR_ERR_OR_ZERO(desc));

-out:
- of_node_put(gpiospec.np);
-
return desc;
}


--
2.56.0.257.gf7497c7d27-goog