gpio: fix deferred probe detection for legacy API
authorAlexandre Courbot <acourbot@nvidia.com>
Tue, 2 Dec 2014 14:15:05 +0000 (23:15 +0900)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 2 Dec 2014 14:46:36 +0000 (15:46 +0100)
Commit 14e85c0e69d5 ("gpio: remove gpio_descs global array") changed
gpio_to_desc()'s behavior to return NULL not only for GPIOs numbers
not in the valid range, but also for all GPIOs whose controller has not
been probed yet. Although this behavior is more correct (nothing hints
that these GPIO numbers will be populated later), this affects
gpio_request() and gpio_request_one() which call gpiod_request() with a
NULL descriptor, causing it to return -EINVAL instead of the expected
-EPROBE_DEFER for a non-probed GPIO.

gpiod_request() is only called with a descriptor obtained from
gpio_to_desc() from these two functions, so address the issue there.

Other ways to obtain GPIOs rely on well-defined mappings and can thus
return -EPROBE_DEFER only for relevant GPIOs, and are thus not affected
by this issue.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib-legacy.c
drivers/gpio/gpiolib.c

index 078ae6c2df795a06daf3354fcdb92c8db657d291..8b830996fe0212d3ae0153ae5b708a84fa53976e 100644 (file)
@@ -24,6 +24,10 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
 
        desc = gpio_to_desc(gpio);
 
+       /* Compatibility: assume unavailable "valid" GPIOs will appear later */
+       if (!desc && gpio_is_valid(gpio))
+               return -EPROBE_DEFER;
+
        err = gpiod_request(desc, label);
        if (err)
                return err;
@@ -62,7 +66,13 @@ EXPORT_SYMBOL_GPL(gpio_request_one);
 
 int gpio_request(unsigned gpio, const char *label)
 {
-       return gpiod_request(gpio_to_desc(gpio), label);
+       struct gpio_desc *desc = gpio_to_desc(gpio);
+
+       /* Compatibility: assume unavailable "valid" GPIOs will appear later */
+       if (!desc && gpio_is_valid(gpio))
+               return -EPROBE_DEFER;
+
+       return gpiod_request(desc, label);
 }
 EXPORT_SYMBOL_GPL(gpio_request);
 
index 0b271ef87c0917267b30c1ec883fd0170e31f2e0..56b7c5de95a02251e97e9ef712d3a9fa88ebddaf 100644 (file)
@@ -77,7 +77,9 @@ struct gpio_desc *gpio_to_desc(unsigned gpio)
 
        spin_unlock_irqrestore(&gpio_lock, flags);
 
-       WARN(1, "invalid GPIO %d\n", gpio);
+       if (!gpio_is_valid(gpio))
+               WARN(1, "invalid GPIO %d\n", gpio);
+
        return NULL;
 }
 EXPORT_SYMBOL_GPL(gpio_to_desc);