gpio: Verify validity of pin offsets from device trees
authorSamuel Holland <samuel@sholland.org>
Sat, 11 Sep 2021 22:05:52 +0000 (17:05 -0500)
committerTom Rini <trini@konsulko.com>
Tue, 5 Oct 2021 12:50:15 +0000 (08:50 -0400)
Translation of an OF GPIO specifier should fail if the pin 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>
drivers/gpio/gpio-uclass.c

index 45a7f8d..fde046e 100644 (file)
@@ -189,10 +189,14 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
                          struct ofnode_phandle_args *args)
 {
+       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
        if (args->args_count < 1)
                return -EINVAL;
 
        desc->offset = args->args[0];
+       if (desc->offset >= uc_priv->gpio_count)
+               return -EINVAL;
 
        if (args->args_count < 2)
                return 0;