summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2021-09-12 01:05:52 +0300
committerTom Rini <trini@konsulko.com>2021-10-05 15:50:15 +0300
commit37c10bf7ef22ccaa349581984340a616fb1c6ffb (patch)
tree2448cfd8c333c96611d78c5952036dbc3c5d83bc
parent390ccffe07c45a3ad584ee6199cc1e63d07981ee (diff)
downloadu-boot-37c10bf7ef22ccaa349581984340a616fb1c6ffb.tar.xz
gpio: Verify validity of pin offsets from device trees
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>
-rw-r--r--drivers/gpio/gpio-uclass.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 45a7f8def4..fde046e8df 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -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;