Re: [PATCH v2] leds: netxbig: fix GPIO descriptor leak in error paths

From: Markus Elfring

Date: Thu Oct 30 2025 - 06:00:24 EST


…> ---
> Changes in v2:
> - Consolidate PTR_ERR(gpiod) extraction into err_gpiod_put label


Thanks.

I see another refinement possibility.


…> +++ b/drivers/leds/leds-netxbig.c
…> @@ -374,46 +377,61 @@ static int netxbig_gpio_ext_get(struct device *dev,
> for (i = 0; i < num_addr; i++) {
> gpiod = gpiod_get_index(gpio_ext_dev, "addr", i,
> GPIOD_OUT_LOW);
> - if (IS_ERR(gpiod))
> - return PTR_ERR(gpiod);
> + if (IS_ERR(gpiod)) {
> + ret = PTR_ERR(gpiod);

Why do propose to add this statement here?


> + goto err_free_addr;
> + }
…> +err_gpiod_put:
> + ret = PTR_ERR(gpiod);
> +err_free_data:
> + for (i = 0; i < gpio_ext->num_data; i++)
> + gpiod_put(gpio_ext->data[i]);


Would you find the following source code usable between the other two labels?

err_set_code:
ret = PTR_ERR(gpiod);


> +err_free_addr:
> + for (i = 0; i < gpio_ext->num_addr; i++)
> + gpiod_put(gpio_ext->addr[i]);
> + return ret;
> }


Regards,
Markus