linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod
@ 2016-02-19  9:58 Geert Uytterhoeven
  2016-02-19 10:01 ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2016-02-19  9:58 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot
  Cc: Olliver Schinagl, linux-gpio, Geert Uytterhoeven

At this point in gpio_keys_polled_probe(), button->gpiod contains either
a pointer to a GPIO descriptor or NULL, because:
  - gpio_keys_polled_get_devtree_pdata() fills in button->gpiod only if
    devm_get_gpiod_from_child() succeeded,
  - gpio_to_desc() returns NULL on failure, not an ERR_PTR(),
  - button->gpiod is untouched if it was NULL, and button->gpio is not
    valid.

Hence check for NULL only, and return -EINVAL on failure.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Question: Should it return -ENOENT instead?
---
 drivers/input/keyboard/gpio_keys_polled.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index 62bdb1d48c49dbd9..1ef3c66099a50d72 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -330,8 +330,8 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
 			button->gpiod = gpio_to_desc(button->gpio);
 		}
 
-		if (IS_ERR(button->gpiod))
-			return PTR_ERR(button->gpiod);
+		if (!button->gpiod)
+			return -EINVAL;
 
 		bdata->can_sleep = gpiod_cansleep(button->gpiod);
 		bdata->last_state = -1;
-- 
1.9.1


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

* Re: [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod
  2016-02-19  9:58 Geert Uytterhoeven
@ 2016-02-19 10:01 ` Geert Uytterhoeven
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2016-02-19 10:01 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Linus Walleij, Alexandre Courbot, Olliver Schinagl,
	linux-gpio@vger.kernel.org

On Fri, Feb 19, 2016 at 10:58 AM, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> At this point in gpio_keys_polled_probe(), button->gpiod contains either
> a pointer to a GPIO descriptor or NULL, because:
>   - gpio_keys_polled_get_devtree_pdata() fills in button->gpiod only if
>     devm_get_gpiod_from_child() succeeded,
>   - gpio_to_desc() returns NULL on failure, not an ERR_PTR(),
>   - button->gpiod is untouched if it was NULL, and button->gpio is not
>     valid.
>
> Hence check for NULL only, and return -EINVAL on failure.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Sorry, scratch this, sent to wrong audience.

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] 5+ messages in thread

* [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod
@ 2016-02-19 10:04 Geert Uytterhoeven
  2016-02-19 10:39 ` Mika Westerberg
  2016-02-22 19:54 ` Dmitry Torokhov
  0 siblings, 2 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2016-02-19 10:04 UTC (permalink / raw)
  To: Dmitry Torokhov, Aaron Lu, Mika Westerberg, Rafael J. Wysocki
  Cc: Linus Walleij, Alexandre Courbot, linux-input, linux-gpio,
	Geert Uytterhoeven

At this point in gpio_keys_polled_probe(), button->gpiod contains either
a pointer to a GPIO descriptor or NULL, because:
  - gpio_keys_polled_get_devtree_pdata() fills in button->gpiod only if
    devm_get_gpiod_from_child() succeeded,
  - gpio_to_desc() returns NULL on failure, not an ERR_PTR(),
  - button->gpiod is untouched if it was NULL, and button->gpio is not
    valid.

Hence check for NULL only, and return -EINVAL on failure.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Question: Should it return -ENOENT instead?

next-20160219:drivers/leds/leds-gpio.c uses -EINVAL, too.
---
 drivers/input/keyboard/gpio_keys_polled.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index 62bdb1d48c49dbd9..1ef3c66099a50d72 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -330,8 +330,8 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
 			button->gpiod = gpio_to_desc(button->gpio);
 		}
 
-		if (IS_ERR(button->gpiod))
-			return PTR_ERR(button->gpiod);
+		if (!button->gpiod)
+			return -EINVAL;
 
 		bdata->can_sleep = gpiod_cansleep(button->gpiod);
 		bdata->last_state = -1;
-- 
1.9.1


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

* Re: [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod
  2016-02-19 10:04 [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod Geert Uytterhoeven
@ 2016-02-19 10:39 ` Mika Westerberg
  2016-02-22 19:54 ` Dmitry Torokhov
  1 sibling, 0 replies; 5+ messages in thread
From: Mika Westerberg @ 2016-02-19 10:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Dmitry Torokhov, Aaron Lu, Rafael J. Wysocki, Linus Walleij,
	Alexandre Courbot, linux-input, linux-gpio

On Fri, Feb 19, 2016 at 11:04:33AM +0100, Geert Uytterhoeven wrote:
> At this point in gpio_keys_polled_probe(), button->gpiod contains either
> a pointer to a GPIO descriptor or NULL, because:
>   - gpio_keys_polled_get_devtree_pdata() fills in button->gpiod only if
>     devm_get_gpiod_from_child() succeeded,
>   - gpio_to_desc() returns NULL on failure, not an ERR_PTR(),
>   - button->gpiod is untouched if it was NULL, and button->gpio is not
>     valid.
> 
> Hence check for NULL only, and return -EINVAL on failure.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

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

* Re: [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod
  2016-02-19 10:04 [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod Geert Uytterhoeven
  2016-02-19 10:39 ` Mika Westerberg
@ 2016-02-22 19:54 ` Dmitry Torokhov
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2016-02-22 19:54 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Aaron Lu, Mika Westerberg, Rafael J. Wysocki, Linus Walleij,
	Alexandre Courbot, linux-input, linux-gpio

On Fri, Feb 19, 2016 at 11:04:33AM +0100, Geert Uytterhoeven wrote:
> At this point in gpio_keys_polled_probe(), button->gpiod contains either
> a pointer to a GPIO descriptor or NULL, because:
>   - gpio_keys_polled_get_devtree_pdata() fills in button->gpiod only if
>     devm_get_gpiod_from_child() succeeded,
>   - gpio_to_desc() returns NULL on failure, not an ERR_PTR(),
>   - button->gpiod is untouched if it was NULL, and button->gpio is not
>     valid.
> 
> Hence check for NULL only, and return -EINVAL on failure.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> Question: Should it return -ENOENT instead?
> 
> next-20160219:drivers/leds/leds-gpio.c uses -EINVAL, too.
> ---
>  drivers/input/keyboard/gpio_keys_polled.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
> index 62bdb1d48c49dbd9..1ef3c66099a50d72 100644
> --- a/drivers/input/keyboard/gpio_keys_polled.c
> +++ b/drivers/input/keyboard/gpio_keys_polled.c
> @@ -330,8 +330,8 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
>  			button->gpiod = gpio_to_desc(button->gpio);
>  		}
>  
> -		if (IS_ERR(button->gpiod))
> -			return PTR_ERR(button->gpiod);
> +		if (!button->gpiod)
> +			return -EINVAL;

I wonder if we should move this check into body of

	if (!button->gpiod && gpio_is_valid(button->gpio)) {
		...
	}

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2016-02-22 19:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-19 10:04 [PATCH] input: gpio_keys_polled: Correct check for invalid gpiod Geert Uytterhoeven
2016-02-19 10:39 ` Mika Westerberg
2016-02-22 19:54 ` Dmitry Torokhov
  -- strict thread matches above, loose matches on Subject: below --
2016-02-19  9:58 Geert Uytterhoeven
2016-02-19 10:01 ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).