All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found
@ 2015-06-10 13:05 Mika Westerberg
  2015-06-10 23:43 ` Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mika Westerberg @ 2015-06-10 13:05 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Rafael J. Wysocki, Andy Shevchenko,
	Tobias Diedrich, Mika Westerberg, linux-gpio, linux-kernel

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@gmail.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 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 19b99d0c2bf0..b49006c81a7f 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);
+		return ERR_PTR(-EPROBE_DEFER);
 
 	offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
 	if (offset < 0)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found
  2015-06-10 13:05 [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found Mika Westerberg
@ 2015-06-10 23:43 ` Rafael J. Wysocki
  2015-06-11  0:11   ` Tobias Diedrich
  2015-06-11  0:29 ` Amos Jianjun Kong
  2015-06-11  8:18 ` Linus Walleij
  2 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2015-06-10 23:43 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Linus Walleij, Alexandre Courbot, Andy Shevchenko,
	Tobias Diedrich, linux-gpio, linux-kernel

On Wednesday, June 10, 2015 04:05:05 PM Mika Westerberg wrote:
> 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@gmail.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Makes sense to me.

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  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 19b99d0c2bf0..b49006c81a7f 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);
> +		return ERR_PTR(-EPROBE_DEFER);
>  
>  	offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
>  	if (offset < 0)
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found
  2015-06-10 23:43 ` Rafael J. Wysocki
@ 2015-06-11  0:11   ` Tobias Diedrich
  0 siblings, 0 replies; 5+ messages in thread
From: Tobias Diedrich @ 2015-06-11  0:11 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mika Westerberg, Linus Walleij, Alexandre Courbot,
	Andy Shevchenko, linux-gpio, linux-kernel

Rafael J. Wysocki wrote:
> On Wednesday, June 10, 2015 04:05:05 PM Mika Westerberg wrote:
> > 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@gmail.com>
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> Makes sense to me.
> 
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: Tobias Diedrich <ranma+kernel@tdiedrich.de>

-- 
Tobias						PGP: http://8ef7ddba.uguu.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found
  2015-06-10 13:05 [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found Mika Westerberg
  2015-06-10 23:43 ` Rafael J. Wysocki
@ 2015-06-11  0:29 ` Amos Jianjun Kong
  2015-06-11  8:18 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Amos Jianjun Kong @ 2015-06-11  0:29 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Linus Walleij, Alexandre Courbot, Rafael J. Wysocki,
	Andy Shevchenko, Tobias Diedrich, linux-gpio, open list

On Wed, Jun 10, 2015 at 9:05 PM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
> 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@gmail.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
>  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 19b99d0c2bf0..b49006c81a7f 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.
>   */
> -

api_get_gpiod() is called in preprobe stage, we still have chance to
probe the device.

Reviewed-by: Amos Kong <kongjianjun@gmail.com>

>  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);
> +               return ERR_PTR(-EPROBE_DEFER);
>
>         offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
>         if (offset < 0)
> --
> 2.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found
  2015-06-10 13:05 [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found Mika Westerberg
  2015-06-10 23:43 ` Rafael J. Wysocki
  2015-06-11  0:29 ` Amos Jianjun Kong
@ 2015-06-11  8:18 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2015-06-11  8:18 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Alexandre Courbot, Rafael J. Wysocki, Andy Shevchenko,
	Tobias Diedrich, linux-gpio, linux-kernel

On Wed, Jun 10, 2015 at 3:05 PM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:

> 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@gmail.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Patch applied with the ACKs etc.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-11  8:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-10 13:05 [PATCH] gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found Mika Westerberg
2015-06-10 23:43 ` Rafael J. Wysocki
2015-06-11  0:11   ` Tobias Diedrich
2015-06-11  0:29 ` Amos Jianjun Kong
2015-06-11  8:18 ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.