From: Samuel Holland <samuel@sholland.org>
Date: Sat, 11 Sep 2021 22:05:51 +0000 (-0500)
Subject: gpio: Verify validity of pin offsets when looking up names
X-Git-Tag: v2025.01-rc5-pxa1908~1693^2~10
X-Git-Url: http://git.dujemihanovic.xyz/img/static/html/%7B%7B?a=commitdiff_plain;h=390ccffe07c45a3ad584ee6199cc1e63d07981ee;p=u-boot.git

gpio: Verify validity of pin offsets when looking up names

Translation of a pin name to a device+offset should fail if the offset
is larger than the number of pins in the GPIO bank.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index bb2f23241e..45a7f8def4 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -141,7 +141,8 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
 
 		if (!strncasecmp(name, uc_priv->bank_name, len)) {
 			if (!strict_strtoul(name + len, 10, &offset))
-				break;
+				if (offset < uc_priv->gpio_count)
+					break;
 		}
 
 		/*