2023-06-05 01:58:44

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH v3] gpio: sifive: Add missing check for platform_get_irq

Add the missing check for platform_get_irq() and return error code
if it fails.

Fixes: f52d6d8b43e5 ("gpio: sifive: To get gpio irq offset from device tree data")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
Changelog:

v2 -> v3:

1. Check before assigning values.

v1 -> v2:

1. Return "girq->parents[0]" instead of "-ENODEV".
---
drivers/gpio/gpio-sifive.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
index 98939cd4a71e..745e5f67254e 100644
--- a/drivers/gpio/gpio-sifive.c
+++ b/drivers/gpio/gpio-sifive.c
@@ -221,8 +221,12 @@ static int sifive_gpio_probe(struct platform_device *pdev)
return -ENODEV;
}

- for (i = 0; i < ngpio; i++)
- chip->irq_number[i] = platform_get_irq(pdev, i);
+ for (i = 0; i < ngpio; i++) {
+ ret = platform_get_irq(pdev, i);
+ if (ret < 0)
+ return ret;
+ chip->irq_number[i] = ret;
+ }

ret = bgpio_init(&chip->gc, dev, 4,
chip->base + SIFIVE_GPIO_INPUT_VAL,
--
2.25.1



2023-06-05 09:23:22

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v3] gpio: sifive: Add missing check for platform_get_irq

On Mon, Jun 5, 2023 at 4:49 AM Jiasheng Jiang <[email protected]> wrote:
>
> Add the missing check for platform_get_irq() and return error code
> if it fails.

Reviewed-by: Andy Shevchenko <[email protected]>

> Fixes: f52d6d8b43e5 ("gpio: sifive: To get gpio irq offset from device tree data")
> Signed-off-by: Jiasheng Jiang <[email protected]>
> ---
> Changelog:
>
> v2 -> v3:
>
> 1. Check before assigning values.
>
> v1 -> v2:
>
> 1. Return "girq->parents[0]" instead of "-ENODEV".
> ---
> drivers/gpio/gpio-sifive.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c
> index 98939cd4a71e..745e5f67254e 100644
> --- a/drivers/gpio/gpio-sifive.c
> +++ b/drivers/gpio/gpio-sifive.c
> @@ -221,8 +221,12 @@ static int sifive_gpio_probe(struct platform_device *pdev)
> return -ENODEV;
> }
>
> - for (i = 0; i < ngpio; i++)
> - chip->irq_number[i] = platform_get_irq(pdev, i);
> + for (i = 0; i < ngpio; i++) {
> + ret = platform_get_irq(pdev, i);
> + if (ret < 0)
> + return ret;
> + chip->irq_number[i] = ret;
> + }
>
> ret = bgpio_init(&chip->gc, dev, 4,
> chip->base + SIFIVE_GPIO_INPUT_VAL,
> --
> 2.25.1
>


--
With Best Regards,
Andy Shevchenko

2023-06-05 09:28:18

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v3] gpio: sifive: Add missing check for platform_get_irq

On Mon, Jun 5, 2023 at 12:13 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Mon, Jun 5, 2023 at 4:49 AM Jiasheng Jiang <[email protected]> wrote:
> >
> > Add the missing check for platform_get_irq() and return error code
> > if it fails.
>
> Reviewed-by: Andy Shevchenko <[email protected]>

Actually, the change is functional and now the wrong IRQ numbering in
the DT will fail the ->probe(). This needs an additional explanation
in the commit message why it's not a problem.

> > - for (i = 0; i < ngpio; i++)
> > - chip->irq_number[i] = platform_get_irq(pdev, i);
> > + for (i = 0; i < ngpio; i++) {
> > + ret = platform_get_irq(pdev, i);
> > + if (ret < 0)
> > + return ret;
> > + chip->irq_number[i] = ret;
> > + }

--
With Best Regards,
Andy Shevchenko

2023-06-06 02:53:58

by Jiasheng Jiang

[permalink] [raw]
Subject: Re: [PATCH v3] gpio: sifive: Add missing check for platform_get_irq

On Mon, 5 Jun 2023 17:15:53 +0800 Andy Shevchenko wrote:
> On Mon, Jun 5, 2023 at 12:13 PM Andy Shevchenko
> <[email protected]> wrote:
>>
>> On Mon, Jun 5, 2023 at 4:49 AM Jiasheng Jiang <[email protected]> wrote:
>> >
>> > Add the missing check for platform_get_irq() and return error code
>> > if it fails.
>>
>> Reviewed-by: Andy Shevchenko <[email protected]>
>
> Actually, the change is functional and now the wrong IRQ numbering in
> the DT will fail the ->probe(). This needs an additional explanation
> in the commit message why it's not a problem.
>
>> > - for (i = 0; i < ngpio; i++)
>> > - chip->irq_number[i] = platform_get_irq(pdev, i);
>> > + for (i = 0; i < ngpio; i++) {
>> > + ret = platform_get_irq(pdev, i);
>> > + if (ret < 0)
>> > + return ret;
>> > + chip->irq_number[i] = ret;
>> > + }

I will submit a new v3 adding the explanation.

Thanks,
Jiasheng


2023-06-06 03:11:51

by Jiasheng Jiang

[permalink] [raw]
Subject: Re: [PATCH v3] gpio: sifive: Add missing check for platform_get_irq

On Mon, 5 Jun 2023 17:15:53 +0800 Andy Shevchenko wrote:
> On Mon, Jun 5, 2023 at 12:13 ?PM Andy Shevchenko
> <[email protected]> wrote:
>>
>> On Mon, Jun 5, 2023 at 4:49 ?AM Jiasheng Jiang <[email protected]> wrote:
>> >
>> > Add the missing check for platform_get_irq() and return error code
>> > if it fails.
>>
>> Reviewed-by: Andy Shevchenko <[email protected]>
>
> Actually, the change is functional and now the wrong IRQ numbering in
> the DT will fail the ->probe(). This needs an additional explanation
> in the commit message why it's not a problem.
>
>> > - for (i = 0; i < ngpio; i++)
>> > - chip->irq_number[i] = platform_get_irq(pdev, i);
>> > + for (i = 0; i < ngpio; i++) {
>> > + ret = platform_get_irq(pdev, i);
>> > + if (ret < 0)
>> > + return ret;
>> > + chip->irq_number[i] = ret;
>> > + }

I will submit a new v3 adding the explanation.

Thanks,
Jiasheng