All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: use better errno if get_direction is not available
@ 2018-07-11 16:33 Wolfram Sang
  2018-07-11 17:24 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Wolfram Sang @ 2018-07-11 16:33 UTC (permalink / raw)
  To: linux-gpio
  Cc: linux-renesas-soc, Linus Walleij, Geert Uytterhoeven, Wolfram Sang

EINVAL is very generic, use ENOTSUPP in case the gpiochip does not
provide this function. While removing the assignment from the 'status'
variable, use better indentation in the declaration block.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

I got puzzled by the EINVAL until I found out that gpio-rcar simply does not
implement it.

@Geert: any reason gpio-rcar is missing it? I would need it for the
i2c-gpio-fault-injector.

 drivers/gpio/gpiolib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e11a3bb03820..18719f64e80b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -210,15 +210,15 @@ static int gpiochip_find_base(int ngpio)
  */
 int gpiod_get_direction(struct gpio_desc *desc)
 {
-	struct gpio_chip	*chip;
-	unsigned		offset;
-	int			status = -EINVAL;
+	struct gpio_chip *chip;
+	unsigned offset;
+	int status;
 
 	chip = gpiod_to_chip(desc);
 	offset = gpio_chip_hwgpio(desc);
 
 	if (!chip->get_direction)
-		return status;
+		return -ENOTSUPP;
 
 	status = chip->get_direction(chip, offset);
 	if (status > 0) {
-- 
2.11.0

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-11 16:33 [PATCH] gpiolib: use better errno if get_direction is not available Wolfram Sang
@ 2018-07-11 17:24 ` Geert Uytterhoeven
  2018-07-11 17:29   ` Wolfram Sang
  2018-07-12 15:51 ` Wolfram Sang
  2018-07-13  8:01 ` Simon Horman
  2 siblings, 1 reply; 11+ messages in thread
From: Geert Uytterhoeven @ 2018-07-11 17:24 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: open list:GPIO SUBSYSTEM, Linux-Renesas, Linus Walleij

Hi Wolfram,

On Wed, Jul 11, 2018 at 6:33 PM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> @Geert: any reason gpio-rcar is missing it? I would need it for the
> i2c-gpio-fault-injector.

Because so far no one had a need for it?
/me thought gpiolib would return a cached value from a previous
set_direction_{in,out}put(), but apparently that must have been a dream...

Do you want me to implement it?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-11 17:24 ` Geert Uytterhoeven
@ 2018-07-11 17:29   ` Wolfram Sang
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfram Sang @ 2018-07-11 17:29 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Wolfram Sang, open list:GPIO SUBSYSTEM, Linux-Renesas, Linus Walleij

[-- Attachment #1: Type: text/plain, Size: 65 bytes --]


> Do you want me to implement it?

Yes, please.

Thanks a lot!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-11 16:33 [PATCH] gpiolib: use better errno if get_direction is not available Wolfram Sang
  2018-07-11 17:24 ` Geert Uytterhoeven
@ 2018-07-12 15:51 ` Wolfram Sang
  2018-07-12 16:31   ` Wolfram Sang
  2018-07-25 20:20   ` Wolfram Sang
  2018-07-13  8:01 ` Simon Horman
  2 siblings, 2 replies; 11+ messages in thread
From: Wolfram Sang @ 2018-07-12 15:51 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-gpio, linux-renesas-soc, Linus Walleij, Geert Uytterhoeven

[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]

On Wed, Jul 11, 2018 at 06:33:19PM +0200, Wolfram Sang wrote:
> EINVAL is very generic, use ENOTSUPP in case the gpiochip does not
> provide this function. While removing the assignment from the 'status'
> variable, use better indentation in the declaration block.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

So, Geert implemented get_direction for gpio-rcar, but this doesn't help
my case sadly. Because I2C is open drain, get_direction returns 'input'
:( As mentioned in a previous discussion, returning '0' and '1' from
get_direction() is confusing. But as it looks now, it also is not
enough. Or we'd need another function from which I could determine the
OUT_OPEN_DRAIN state.

For the short term, I will remove the sanity check from the I2C core and
hope the user properly set up the GPIO. It would be nice to check for it
somewhen in the future, though.

That all being said, I think this patch is still useful as is.

Thanks,

   Wolfram

> ---
> 
> I got puzzled by the EINVAL until I found out that gpio-rcar simply does not
> implement it.
> 
> @Geert: any reason gpio-rcar is missing it? I would need it for the
> i2c-gpio-fault-injector.
> 
>  drivers/gpio/gpiolib.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index e11a3bb03820..18719f64e80b 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -210,15 +210,15 @@ static int gpiochip_find_base(int ngpio)
>   */
>  int gpiod_get_direction(struct gpio_desc *desc)
>  {
> -	struct gpio_chip	*chip;
> -	unsigned		offset;
> -	int			status = -EINVAL;
> +	struct gpio_chip *chip;
> +	unsigned offset;
> +	int status;
>  
>  	chip = gpiod_to_chip(desc);
>  	offset = gpio_chip_hwgpio(desc);
>  
>  	if (!chip->get_direction)
> -		return status;
> +		return -ENOTSUPP;
>  
>  	status = chip->get_direction(chip, offset);
>  	if (status > 0) {
> -- 
> 2.11.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-12 15:51 ` Wolfram Sang
@ 2018-07-12 16:31   ` Wolfram Sang
  2018-07-25 20:20   ` Wolfram Sang
  1 sibling, 0 replies; 11+ messages in thread
From: Wolfram Sang @ 2018-07-12 16:31 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-gpio, linux-renesas-soc, Linus Walleij, Geert Uytterhoeven

[-- Attachment #1: Type: text/plain, Size: 225 bytes --]


> For the short term, I will remove the sanity check from the I2C core and
> hope the user properly set up the GPIO.

For the record, this patch is here:

http://patchwork.ozlabs.org/patch/943115/

Forgot to cc linux-gpio.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-11 16:33 [PATCH] gpiolib: use better errno if get_direction is not available Wolfram Sang
  2018-07-11 17:24 ` Geert Uytterhoeven
  2018-07-12 15:51 ` Wolfram Sang
@ 2018-07-13  8:01 ` Simon Horman
  2 siblings, 0 replies; 11+ messages in thread
From: Simon Horman @ 2018-07-13  8:01 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-gpio, linux-renesas-soc, Linus Walleij, Geert Uytterhoeven

On Wed, Jul 11, 2018 at 06:33:19PM +0200, Wolfram Sang wrote:
> EINVAL is very generic, use ENOTSUPP in case the gpiochip does not
> provide this function. While removing the assignment from the 'status'
> variable, use better indentation in the declaration block.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Simon Horman <horms+renesas@verge.net.au>

> ---
> 
> I got puzzled by the EINVAL until I found out that gpio-rcar simply does not
> implement it.
> 
> @Geert: any reason gpio-rcar is missing it? I would need it for the
> i2c-gpio-fault-injector.
> 
>  drivers/gpio/gpiolib.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index e11a3bb03820..18719f64e80b 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -210,15 +210,15 @@ static int gpiochip_find_base(int ngpio)
>   */
>  int gpiod_get_direction(struct gpio_desc *desc)
>  {
> -	struct gpio_chip	*chip;
> -	unsigned		offset;
> -	int			status = -EINVAL;
> +	struct gpio_chip *chip;
> +	unsigned offset;
> +	int status;
>  
>  	chip = gpiod_to_chip(desc);
>  	offset = gpio_chip_hwgpio(desc);
>  
>  	if (!chip->get_direction)
> -		return status;
> +		return -ENOTSUPP;
>  
>  	status = chip->get_direction(chip, offset);
>  	if (status > 0) {
> -- 
> 2.11.0
> 

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-12 15:51 ` Wolfram Sang
  2018-07-12 16:31   ` Wolfram Sang
@ 2018-07-25 20:20   ` Wolfram Sang
  2018-07-29 21:33     ` Linus Walleij
  1 sibling, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2018-07-25 20:20 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-gpio, linux-renesas-soc, Linus Walleij, Geert Uytterhoeven

[-- Attachment #1: Type: text/plain, Size: 112 bytes --]


> That all being said, I think this patch is still useful as is.

Linus, do you have time to comment on this?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-25 20:20   ` Wolfram Sang
@ 2018-07-29 21:33     ` Linus Walleij
  2018-09-11 12:03       ` Geert Uytterhoeven
  0 siblings, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2018-07-29 21:33 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Wolfram Sang, open list:GPIO SUBSYSTEM, Linux-Renesas,
	Geert Uytterhoeven

On Wed, Jul 25, 2018 at 10:20 PM Wolfram Sang <wsa@the-dreams.de> wrote:

> > That all being said, I think this patch is still useful as is.
>
> Linus, do you have time to comment on this?

This looks like a good solution to me.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-07-29 21:33     ` Linus Walleij
@ 2018-09-11 12:03       ` Geert Uytterhoeven
  2018-09-14  8:46         ` Linus Walleij
  0 siblings, 1 reply; 11+ messages in thread
From: Geert Uytterhoeven @ 2018-09-11 12:03 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Wolfram Sang, Wolfram Sang, open list:GPIO SUBSYSTEM, Linux-Renesas

Hi Linus,

On Sun, Jul 29, 2018 at 11:33 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> On Wed, Jul 25, 2018 at 10:20 PM Wolfram Sang <wsa@the-dreams.de> wrote:
> > > That all being said, I think this patch is still useful as is.
> >
> > Linus, do you have time to comment on this?
>
> This looks like a good solution to me.
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Any plans to apply it? drivers/gpio/gpiolib.c is your territory, I believe ;-)

Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-09-11 12:03       ` Geert Uytterhoeven
@ 2018-09-14  8:46         ` Linus Walleij
  2018-09-14  8:52           ` Wolfram Sang
  0 siblings, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2018-09-14  8:46 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Wolfram Sang, Wolfram Sang, open list:GPIO SUBSYSTEM, Linux-Renesas

On Tue, Sep 11, 2018 at 2:04 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Sun, Jul 29, 2018 at 11:33 PM Linus Walleij <linus.walleij@linaro.org> wrote:> > On Wed, Jul 25, 2018 at 10:20 PM Wolfram Sang <wsa@the-dreams.de> wrote:
> > > > That all being said, I think this patch is still useful as is.
> > >
> > > Linus, do you have time to comment on this?
> >
> > This looks like a good solution to me.
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>
> Any plans to apply it? drivers/gpio/gpiolib.c is your territory, I believe ;-)

Ooops sorry.

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH] gpiolib: use better errno if get_direction is not available
  2018-09-14  8:46         ` Linus Walleij
@ 2018-09-14  8:52           ` Wolfram Sang
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfram Sang @ 2018-09-14  8:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Geert Uytterhoeven, Wolfram Sang, open list:GPIO SUBSYSTEM,
	Linux-Renesas

[-- Attachment #1: Type: text/plain, Size: 155 bytes --]


> > Any plans to apply it? drivers/gpio/gpiolib.c is your territory, I believe ;-)
> 
> Ooops sorry.
> 
> Patch applied.

Thanks Geert & Linus!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2018-09-14 14:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-11 16:33 [PATCH] gpiolib: use better errno if get_direction is not available Wolfram Sang
2018-07-11 17:24 ` Geert Uytterhoeven
2018-07-11 17:29   ` Wolfram Sang
2018-07-12 15:51 ` Wolfram Sang
2018-07-12 16:31   ` Wolfram Sang
2018-07-25 20:20   ` Wolfram Sang
2018-07-29 21:33     ` Linus Walleij
2018-09-11 12:03       ` Geert Uytterhoeven
2018-09-14  8:46         ` Linus Walleij
2018-09-14  8:52           ` Wolfram Sang
2018-07-13  8:01 ` Simon Horman

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.