[linux-yocto] [PATCH 11/19] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found

Saul Wold sgw at linux.intel.com
Mon Feb 8 14:10:20 PST 2016

From: Mika Westerberg <mika.westerberg at linux.intel.com>

commit d8213ae03aebde8074f071d1da48007d55e3b41d upstream.

If a driver requests a GPIO described in its _CRS but the GPIO host
controller (gpiochip) driver providing the GPIO has not been loaded yet
acpi_get_gpiod() returns -ENODEV which causes the calling driver to fail.

If the gpiochip driver is loaded afterwards the driver requesting the GPIO
will not notice this.

Better approach is to return -EPROBE_DEFER in such case. Then when the
gpiochip driver appears the driver requesting the GPIO will be probed
again. This also aligns ACPI GPIO lookup code closer to DT as it does
pretty much the same when no gpiochip driver was found.

Reported-by: Tobias Diedrich <tobiasdiedrich at gmail.com>
Signed-off-by: Mika Westerberg <mika.westerberg at linux.intel.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
Signed-off-by: Tobias Diedrich <ranma+kernel at tdiedrich.de>
Reviewed-by: Amos Kong <kongjianjun at gmail.com>
Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
(cherry picked from commit f35bbf61ab772cc312f64dddd1c89ab161893cee)
 drivers/gpio/gpiolib-acpi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 980a996..533fe5d 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -114,10 +114,11 @@ static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip,
  * @path:	ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
  * @pin:	ACPI GPIO pin number (0-based, controller-relative)
- * Returns GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
- * error value
+ * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
+ * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
+ * controller does not have gpiochip registered at the moment. This is to
+ * support probe deferral.
 static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 	struct gpio_chip *chip;
@@ -131,7 +132,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 	chip = gpiochip_find(handle, acpi_gpiochip_find);
 	if (!chip)
-		return ERR_PTR(-ENODEV);
 	offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
 	if (offset < 0)

More information about the linux-yocto mailing list