[PATCH 02/10] gpiolib: simplify for loop break condition

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Jun 13 00:37:34 PDT 2023


On 02.06.23 09:49, Marco Felsch wrote:
> No functional change just a simplification to align it with the Linux
> kernel. Also add the kernel comment to make the reason clear.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

> ---
>  drivers/gpio/gpiolib.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index b4a3a4e550..0df43c9f8f 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -529,7 +529,15 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
>  		of_property_read_string_array(chip->dev->of_node,
>  					      "gpio-line-names", arr, count);
>  
> -		for (i = 0; i < chip->ngpio && i < count; i++)
> +		/*
> +		 * Since property 'gpio-line-names' cannot contains gaps, we
> +		 * have to be sure we only assign those pins that really exists
> +		 * since chip->ngpio can be less.
> +		 */
> +		if (count > chip->ngpio)
> +			count = chip->ngpio;
> +
> +		for (i = 0; i < count; i++)
>  			gpio_desc[chip->base + i].name = xstrdup(arr[i]);
>  
>  		free(arr);

-- 
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 |




More information about the barebox mailing list