[PATCH] gpiolib: Put fwnode reference on failure

Michail Tatas posted 1 patch 1 month, 3 weeks ago
There is a newer version of this series
drivers/gpio/gpiolib-shared.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
[PATCH] gpiolib: Put fwnode reference on failure
Posted by Michail Tatas 1 month, 3 weeks ago
We get a reference to the fwnode handle which we pass to
gpio_shared_make_ref. In case it fails we do not put the reference. 
Fix by putting the reference in the failure case

Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
---
 drivers/gpio/gpiolib-shared.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index 495bd3d0ddf0..5f9623e40b0f 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -261,10 +261,13 @@ static int gpio_shared_of_traverse(struct device_node *curr)
 				con_id[con_id_len - suffix_len] = '\0';
 			}
 
-			ref = gpio_shared_make_ref(fwnode_handle_get(of_fwnode_handle(curr)),
-						   con_id, args.args[1]);
-			if (!ref)
+			struct fwnode_handle *curr_fwnode =
+				fwnode_handle_get(of_fwnode_handle(curr));
+			ref = gpio_shared_make_ref(curr_fwnode, con_id, args.args[1]);
+			if (!ref) {
+				fwnode_handle_put(curr_fwnode);
 				return -ENOMEM;
+			}
 
 			if (!list_empty(&entry->refs))
 				pr_debug("GPIO %u at %s is shared by multiple firmware nodes\n",
-- 
2.43.0
Re: [PATCH] gpiolib: Put fwnode reference on failure
Posted by Bartosz Golaszewski 1 month, 2 weeks ago
On Thu, 6 Aug 2026 23:47:35 +0200, Michail Tatas <michail.tatas@gmail.com> said:
> We get a reference to the fwnode handle which we pass to
> gpio_shared_make_ref. In case it fails we do not put the reference.
> Fix by putting the reference in the failure case
>
> Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
> ---

Can you add the Fixes: and Cc: stable tags please?

Bart