Re: [PATCH 04/10] gpiolib: fix gpio name memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02.06.23 09:49, Marco Felsch wrote:
> We never freed the name allocated by xstrdup(). Fix this by use the
> const devicetree property value. While on it check if the name is valid
> and add the comment to align the code with the kernel.
> 
> Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx>

Reviewed-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>

> ---
>  drivers/gpio/gpiolib.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index eb2bba042e..f05e2ac735 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -18,7 +18,7 @@ struct gpio_info {
>  	bool requested;
>  	bool active_low;
>  	char *label;
> -	char *name;
> +	const char *name;
>  };
>  
>  static struct gpio_info *gpio_desc;
> @@ -537,8 +537,16 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
>  		if (count > chip->ngpio)
>  			count = chip->ngpio;
>  
> -		for (i = 0; i < count; i++)
> -			gpio_desc[chip->base + i].name = xstrdup(names[i]);
> +		for (i = 0; i < count; i++) {
> +			/*
> +			 * Allow overriding "fixed" names provided by the GPIO
> +			 * provider. The "fixed" names are more often than not
> +			 * generic and less informative than the names given in
> +			 * device properties.
> +			 */
> +			if (names[i] && names[i][0])
> +				gpio_desc[chip->base + i].name = names[i];
> +		}
>  
>  		free(names);
>  	}

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux