diff mbox

[U-Boot,39/55] dm: gpio: Check a GPIO is valid before using it

Message ID 1435882592-487-40-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass July 3, 2015, 12:16 a.m. UTC
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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Simon Glass July 27, 2015, 11:31 p.m. UTC | #1
On 2 July 2015 at 18:16, Simon Glass <sjg@chromium.org> wrote:
> 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 | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index c4ba580..b951662 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,