diff mbox

input: gpio_keys_polled: Correct check for invalid gpiod

Message ID 1455876273-5913-1-git-send-email-geert+renesas@glider.be (mailing list archive)
State New, archived
Headers show

Commit Message

Geert Uytterhoeven Feb. 19, 2016, 10:04 a.m. UTC
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(-)

Comments

Mika Westerberg Feb. 19, 2016, 10:39 a.m. UTC | #1
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>
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov Feb. 22, 2016, 7:54 p.m. UTC | #2
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.
diff mbox

Patch

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;