]> git.sur5r.net Git - u-boot/commitdiff
dm: gpio: Check a GPIO is valid before using it
authorSimon Glass <sjg@chromium.org>
Fri, 3 Jul 2015 00:16:16 +0000 (18:16 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 6 Aug 2015 03:06:14 +0000 (21:06 -0600)
Since a gpio_desc is allowed to be invalid we should return an error
indicating that the operation cannot be completed. This can happen if the
GPIO is optional - e.g. some devices may have a reset line and some may
not.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/gpio/gpio-uclass.c

index 4efda311a49e81c8470a23d88f62a09b07f0f5bc..4cce11fe215f05b2cfbc1d55b5c4e020940b1ee6 100644 (file)
@@ -250,8 +250,12 @@ int gpio_free(unsigned gpio)
 
 static int check_reserved(struct gpio_desc *desc, const char *func)
 {
-       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(desc->dev);
+       struct gpio_dev_priv *uc_priv;
+
+       if (!dm_gpio_is_valid(desc))
+               return -ENOENT;
 
+       uc_priv = dev_get_uclass_priv(desc->dev);
        if (!uc_priv->name[desc->offset]) {
                printf("%s: %s: error: gpio %s%d not reserved\n",
                       desc->dev->name, func,