From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Date: Fri, 10 Mar 2023 10:58:03 +0000 (+0100)
Subject: sysinfo: gpio: fix loop over DT "revisions" array
X-Git-Tag: v2025.01-rc5-pxa1908~1023^2~17^2~18
X-Git-Url: http://git.dujemihanovic.xyz/html/static/git-logo.png?a=commitdiff_plain;h=19213d7a65e9e3f8cfd0852599170636c894169e;p=u-boot.git

sysinfo: gpio: fix loop over DT "revisions" array

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

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