U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@seco.com>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>, u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH] sysinfo: gpio: fix loop over DT "revisions" array
Date: Mon, 13 Mar 2023 11:23:02 -0400	[thread overview]
Message-ID: <c2a5172c-39f0-8d22-fb4d-68693ac4212b@seco.com> (raw)
In-Reply-To: <20230310105803.1824795-1-rasmus.villemoes@prevas.dk>

On 3/10/23 05:58, Rasmus Villemoes wrote:
> There can certainly be a lot more elements in the "revisions" (and
> "names") arrays than there are gpios used to form the trinary number
> we're searching for; we simply don't know the array size up-front.
> 
> Nor do we need to, because the loop body already knows to recognize
> -EOVERFLOW as "not that many elements present" (and we have a test
> that specifically ensures that dev_read_u32_index() returns exactly
> that). So just drop the i < priv->gpio_num condition.
> 
> While in here, fix the weird placement of the default: keyword.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>  drivers/sysinfo/gpio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/sysinfo/gpio.c b/drivers/sysinfo/gpio.c
> index 1d7f050998..82f90303bb 100644
> --- a/drivers/sysinfo/gpio.c
> +++ b/drivers/sysinfo/gpio.c
> @@ -57,7 +57,7 @@ static int sysinfo_gpio_get_str(struct udevice *dev, int id, size_t size, char *
>  		int i, ret;
>  		u32 revision;
>  
> -		for (i = 0; i < priv->gpio_num; i++) {
> +		for (i = 0; ; i++) {
>  			ret = dev_read_u32_index(dev, "revisions", i,
>  						 &revision);
>  			if (ret) {
> @@ -80,7 +80,8 @@ static int sysinfo_gpio_get_str(struct udevice *dev, int id, size_t size, char *
>  		strncpy(val, name, size);
>  		val[size - 1] = '\0';
>  		return 0;
> -	} default:
> +	}
> +	default:
>  		return -EINVAL;
>  	};
>  }

Reviewed-by: Sean Anderson <sean.anderson@seco.com>

  parent reply	other threads:[~2023-03-13 15:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 10:58 [PATCH] sysinfo: gpio: fix loop over DT "revisions" array Rasmus Villemoes
2023-03-10 20:49 ` Simon Glass
2023-03-13 15:23 ` Sean Anderson [this message]
2023-03-31 14:16 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c2a5172c-39f0-8d22-fb4d-68693ac4212b@seco.com \
    --to=sean.anderson@seco.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox