* [PATCH] sysinfo: gpio: fix loop over DT "revisions" array
@ 2023-03-10 10:58 Rasmus Villemoes
2023-03-10 20:49 ` Simon Glass
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rasmus Villemoes @ 2023-03-10 10:58 UTC (permalink / raw)
To: u-boot; +Cc: Sean Anderson, Simon Glass, Tom Rini, Rasmus Villemoes
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;
};
}
--
2.37.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sysinfo: gpio: fix loop over DT "revisions" array
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
2023-03-31 14:16 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2023-03-10 20:49 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: u-boot, Sean Anderson, Tom Rini
On Fri, 10 Mar 2023 at 02:58, Rasmus Villemoes
<rasmus.villemoes@prevas.dk> 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(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sysinfo: gpio: fix loop over DT "revisions" array
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
2023-03-31 14:16 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Sean Anderson @ 2023-03-13 15:23 UTC (permalink / raw)
To: Rasmus Villemoes, u-boot; +Cc: Simon Glass, Tom Rini
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sysinfo: gpio: fix loop over DT "revisions" array
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
@ 2023-03-31 14:16 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2023-03-31 14:16 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: u-boot, Sean Anderson, Simon Glass
[-- Attachment #1: Type: text/plain, Size: 842 bytes --]
On Fri, Mar 10, 2023 at 11:58:03AM +0100, 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>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Sean Anderson <sean.anderson@seco.com>
Applied to u-boot/next, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-31 14:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2023-03-31 14:16 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox