[PATCH 2/3] gpio: delay: set gpio_count and validate index against it

Pranav Sanwal pranav.sanwal at amd.com
Thu Jul 9 16:29:00 CEST 2026


gpio_delay_probe() never set the uclass's gpio_count for this
device, leaving it at 0. This left gpio_post_probe()'s claimed/name
tracking arrays sized for zero entries, and left gpio_delay_xlate()'s
bounds check validating the requested index against a hardcoded 32
that has no relation to how many lines this instance actually
manages (ngpio, from its own "gpios" property).

Set gpio_count in probe() to the real count, and validate against it
in xlate(), matching the pattern already used by the generic
gpio_xlate_offs_flags() default implementation.

Fixes: c866f2f197e2 ("gpio: Add GPIO delay driver")
Signed-off-by: Pranav Sanwal <pranav.sanwal at amd.com>
---
 drivers/gpio/gpio-delay.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-delay.c b/drivers/gpio/gpio-delay.c
index 9105deecc4f..533e7d2f8ef 100644
--- a/drivers/gpio/gpio-delay.c
+++ b/drivers/gpio/gpio-delay.c
@@ -68,12 +68,13 @@ static int gpio_delay_direction_output(struct udevice *dev, unsigned int offset,
 static int gpio_delay_xlate(struct udevice *dev, struct gpio_desc *desc,
 			    struct ofnode_phandle_args *args)
 {
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 	struct gpio_delay_priv *priv = dev_get_priv(dev);
 
 	if (args->args_count < 3)
 		return -EINVAL;
 
-	if (args->args[0] >= 32)
+	if (args->args[0] >= uc_priv->gpio_count)
 		return -EINVAL;
 
 	struct gpio_delay_desc *d = &priv->descs[args->args[0]];
@@ -97,6 +98,7 @@ static const struct dm_gpio_ops gpio_delay_ops = {
 
 static int gpio_delay_probe(struct udevice *dev)
 {
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 	struct gpio_delay_priv *priv = dev_get_priv(dev);
 	struct gpio_delay_desc *d;
 	ofnode node = dev_ofnode(dev);
@@ -112,6 +114,8 @@ static int gpio_delay_probe(struct udevice *dev)
 	if (!priv->descs)
 		return -ENOMEM;
 
+	uc_priv->gpio_count = ngpio;
+
 	/* Request all GPIOs described in the controller node */
 	for (i = 0; i < ngpio; i++) {
 		d = &priv->descs[i];
-- 
2.34.1



More information about the U-Boot mailing list