diff mbox series

gpio: ftgpio010: Fix platform_get_irq's error checking

Message ID c6bf37f60d82aa3d425f66f08e10fedc51202b6f.1512051063.git.arvind.yadav.cs@gmail.com
State New
Headers show
Series gpio: ftgpio010: Fix platform_get_irq's error checking | expand

Commit Message

Arvind Yadav Nov. 30, 2017, 2:12 p.m. UTC
The platform_get_irq() function returns negative if an error occurs.
zero or positive number on success. platform_get_irq() error checking
for zero is not correct.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
 drivers/gpio/gpio-ftgpio010.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Linus Walleij Dec. 2, 2017, 3:30 p.m. UTC | #1
Hi Arvind,

thanks for the patch!

On Thu, Nov 30, 2017 at 3:12 PM, Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:

> The platform_get_irq() function returns negative if an error occurs.
> zero or positive number on success. platform_get_irq() error checking
> for zero is not correct.
>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
(...)
>         irq = platform_get_irq(pdev, 0);
> -       if (!irq)
> -               return -EINVAL;
> +       if (irq < 0)
> +               return irq;

This is wrong.
For an in-depth explanation why irq 0 in not valid, see:
https://lwn.net/Articles/470820/

It should be:

if (irq <= 0)
  return irq ? irq : -EINVAL;

Please update and resubmit. If you have more patches like this,
correct them too.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arvind Yadav Dec. 2, 2017, 4:49 p.m. UTC | #2
Hi Linus,

On Saturday 02 December 2017 09:00 PM, Linus Walleij wrote:
> Hi Arvind,
>
> thanks for the patch!
>
> On Thu, Nov 30, 2017 at 3:12 PM, Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
>
>> The platform_get_irq() function returns negative if an error occurs.
>> zero or positive number on success. platform_get_irq() error checking
>> for zero is not correct.
>>
>> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> (...)
>>          irq = platform_get_irq(pdev, 0);
>> -       if (!irq)
>> -               return -EINVAL;
>> +       if (irq < 0)
>> +               return irq;
> This is wrong.
> For an in-depth explanation why irq 0 in not valid, see:
> https://lwn.net/Articles/470820/
Thank you for sharing this Articles. It's really helpful.
>
> It should be:
>
> if (irq <= 0)
>    return irq ? irq : -EINVAL;
>
> Please update and resubmit. If you have more patches like this,
> correct them too.
I will resubmit patch.
> Yours,
> Linus Walleij
Thanks,
arvind
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-ftgpio010.c b/drivers/gpio/gpio-ftgpio010.c
index 7b3394f..feff86a 100644
--- a/drivers/gpio/gpio-ftgpio010.c
+++ b/drivers/gpio/gpio-ftgpio010.c
@@ -176,8 +176,8 @@  static int ftgpio_gpio_probe(struct platform_device *pdev)
 		return PTR_ERR(g->base);
 
 	irq = platform_get_irq(pdev, 0);
-	if (!irq)
-		return -EINVAL;
+	if (irq < 0)
+		return irq;
 
 	ret = bgpio_init(&g->gc, dev, 4,
 			 g->base + GPIO_DATA_IN,