summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-07-02 18:16:16 -0600
committerSimon Glass <sjg@chromium.org>2015-08-05 21:06:14 -0600
commiteca4866586ca36a47cd94811a294ac62ebd17abc (patch)
tree63862258962754b9443a4737822feb54be7155b5 /drivers/gpio
parent71db6341c53038db5a73343da2c559dea6c89a7a (diff)
downloadu-boot-imx-eca4866586ca36a47cd94811a294ac62ebd17abc.zip
u-boot-imx-eca4866586ca36a47cd94811a294ac62ebd17abc.tar.gz
u-boot-imx-eca4866586ca36a47cd94811a294ac62ebd17abc.tar.bz2
dm: gpio: Check a GPIO is valid before using it
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>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-uclass.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 4efda31..4cce11f 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -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,