linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
@ 2023-06-05  1:53 Jiasheng Jiang
  2023-06-05  9:20 ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jiasheng Jiang @ 2023-06-05  1:53 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: oe-kbuild-all, linus.walleij, brgl, palmer, paul.walmsley,
	linux-gpio, linux-riscv, linux-kernel, Jiasheng Jiang

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

Fixes: 2b8f89e19b6d ("gpio: ath79: Add support for the interrupt controller")

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:

v2 -> v3:

1. Check before assigning values.

v1 -> v2:

1. Return "girq->parents[0]" instead of "-ENODEV".
---
 drivers/gpio/gpio-ath79.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index aa0a954b8392..d2d838ad33bb 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -285,7 +285,10 @@ static int ath79_gpio_probe(struct platform_device *pdev)
 					     GFP_KERNEL);
 		if (!girq->parents)
 			return -ENOMEM;
-		girq->parents[0] = platform_get_irq(pdev, 0);
+		err = platform_get_irq(pdev, 0);
+		if (err < 0)
+			return err;
+		girq->parents[0] = err;
 		girq->default_type = IRQ_TYPE_NONE;
 		girq->handler = handle_simple_irq;
 	}
-- 
2.25.1


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

* Re: [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
  2023-06-05  1:53 Jiasheng Jiang
@ 2023-06-05  9:20 ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-06-05  9:20 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: oe-kbuild-all, linus.walleij, brgl, palmer, paul.walmsley,
	linux-gpio, linux-riscv, linux-kernel

On Mon, Jun 5, 2023 at 4:53 AM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> Add the missing check for platform_get_irq() and return error
> if it fails.

Here it seems better, but still needs an explanation why returning an
error is not a problem (assuming DT might have a wrong number). I.o.w.
you need to prove that with current code this fails in that case
further. Otherwise you will need to prove that there may not be DT
with a wrong number.

-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
@ 2023-06-06  3:18 Jiasheng Jiang
  2023-06-06  9:28 ` andy.shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jiasheng Jiang @ 2023-06-06  3:18 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: oe-kbuild-all, linus.walleij, brgl, palmer, paul.walmsley,
	linux-gpio, linux-riscv, linux-kernel, Jiasheng Jiang

Add the missing check for platform_get_irq() and return error
if it fails.
The returned error code will be dealed with in
module_platform_driver(ath79_gpio_driver) and the driver will not
be registered.

Fixes: 2b8f89e19b6d ("gpio: ath79: Add support for the interrupt controller")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:

v2 -> v3:

1. Check before assigning values.

v1 -> v2:

1. Return "girq->parents[0]" instead of "-ENODEV".
---
 drivers/gpio/gpio-ath79.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index aa0a954b8392..d2d838ad33bb 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -285,7 +285,10 @@ static int ath79_gpio_probe(struct platform_device *pdev)
 					     GFP_KERNEL);
 		if (!girq->parents)
 			return -ENOMEM;
-		girq->parents[0] = platform_get_irq(pdev, 0);
+		err = platform_get_irq(pdev, 0);
+		if (err < 0)
+			return err;
+		girq->parents[0] = err;
 		girq->default_type = IRQ_TYPE_NONE;
 		girq->handler = handle_simple_irq;
 	}
-- 
2.25.1


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

* Re: [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
  2023-06-06  3:18 [PATCH v3] gpio: ath79: Add missing check for platform_get_irq Jiasheng Jiang
@ 2023-06-06  9:28 ` andy.shevchenko
  2023-06-06  9:46   ` andy.shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: andy.shevchenko @ 2023-06-06  9:28 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: andy.shevchenko, oe-kbuild-all, linus.walleij, brgl, palmer,
	paul.walmsley, linux-gpio, linux-riscv, linux-kernel

Tue, Jun 06, 2023 at 11:18:41AM +0800, Jiasheng Jiang kirjoitti:

Is this v4?

> Add the missing check for platform_get_irq() and return error
> if it fails.
> The returned error code will be dealed with in
> module_platform_driver(ath79_gpio_driver) and the driver will not
> be registered.

No, this functional change and has not to be for the fixes unless _this_ is the
regression you are fixing. Did the driver work before at some point as after
this change?

Otherwise you have to _justify_ that this functional change won't break
existing setups (with broked IRQ in Device Tree, for example).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
  2023-06-06  9:28 ` andy.shevchenko
@ 2023-06-06  9:46   ` andy.shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: andy.shevchenko @ 2023-06-06  9:46 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: Jiasheng Jiang, oe-kbuild-all, linus.walleij, brgl, palmer,
	paul.walmsley, linux-gpio, linux-riscv, linux-kernel

Tue, Jun 06, 2023 at 12:28:17PM +0300, andy.shevchenko@gmail.com kirjoitti:
> Tue, Jun 06, 2023 at 11:18:41AM +0800, Jiasheng Jiang kirjoitti:
> 
> Is this v4?
> 
> > Add the missing check for platform_get_irq() and return error
> > if it fails.
> > The returned error code will be dealed with in
> > module_platform_driver(ath79_gpio_driver) and the driver will not
> > be registered.
> 
> No, this functional change and has not to be for the fixes unless _this_ is the
> regression you are fixing. Did the driver work before at some point as after
> this change?

To be more clear, answer to the following questions:
1) does driver work with wrong DT configuration?
2a) if yes, does it make sense, i.e. the hardware functioning usefully?
2b) if yes, can we guarantee there are no broken configurations in the wild?

Depending on the answers correct your code and/or commit message.

> Otherwise you have to _justify_ that this functional change won't break
> existing setups (with broked IRQ in Device Tree, for example).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
@ 2023-06-07  7:08 Jiasheng Jiang
  2023-06-07 14:49 ` andy.shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jiasheng Jiang @ 2023-06-07  7:08 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: oe-kbuild-all, linus.walleij, brgl, palmer, paul.walmsley,
	linux-gpio, linux-riscv, linux-kernel, Jiasheng Jiang

On Tue, 6 Jun 2023 17:46:36 +0800 Andy Shevchenko wrote:
> Tue, Jun 06, 2023 at 12:28:17PM +0300, andy.shevchenko@gmail.com kirjoitti:
>> Tue, Jun 06, 2023 at 11:18:41AM +0800, Jiasheng Jiang kirjoitti:
>> 
>> Is this v4?
>>

I will submit a v4.
 
>> > Add the missing check for platform_get_irq() and return error
>> > if it fails.
>> > The returned error code will be dealed with in
>> > module_platform_driver(ath79_gpio_driver) and the driver will not
>> > be registered.
>> 
>> No, this functional change and has not to be for the fixes unless _this_ is the
>> regression you are fixing. Did the driver work before at some point as after
>> this change?

I will remove the fixes tag in v4.

> 
> To be more clear, answer to the following questions:
> 1) does driver work with wrong DT configuration?
> 2a) if yes, does it make sense, i.e. the hardware functioning usefully?
> 2b) if yes, can we guarantee there are no broken configurations in the wild?
> 
> Depending on the answers correct your code and/or commit message.
> 
>> Otherwise you have to _justify_ that this functional change won't break
>> existing setups (with broked IRQ in Device Tree, for example).

Sorry, I do not quite understand what you mean.
I have no idea how these questions are related to my patch.
Do you mean I should not fail the ->probe() if there is wrong IRQ numbering in the DT?
Please tell me the relationship between these questions and my patch.

Thanks,
Jiasheng


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

* Re: [PATCH v3] gpio: ath79: Add missing check for platform_get_irq
  2023-06-07  7:08 Jiasheng Jiang
@ 2023-06-07 14:49 ` andy.shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: andy.shevchenko @ 2023-06-07 14:49 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: andy.shevchenko, oe-kbuild-all, linus.walleij, brgl, palmer,
	paul.walmsley, linux-gpio, linux-riscv, linux-kernel

Wed, Jun 07, 2023 at 03:08:19PM +0800, Jiasheng Jiang kirjoitti:
> On Tue, 6 Jun 2023 17:46:36 +0800 Andy Shevchenko wrote:
> > Tue, Jun 06, 2023 at 12:28:17PM +0300, andy.shevchenko@gmail.com kirjoitti:
> >> Tue, Jun 06, 2023 at 11:18:41AM +0800, Jiasheng Jiang kirjoitti:

...

> >> > Add the missing check for platform_get_irq() and return error
> >> > if it fails.
> >> > The returned error code will be dealed with in
> >> > module_platform_driver(ath79_gpio_driver) and the driver will not
> >> > be registered.
> >> 
> >> No, this functional change and has not to be for the fixes unless _this_ is the
> >> regression you are fixing. Did the driver work before at some point as after
> >> this change?
> 
> I will remove the fixes tag in v4.
> 
> > To be more clear, answer to the following questions:
> > 1) does driver work with wrong DT configuration?
> > 2a) if yes, does it make sense, i.e. the hardware functioning usefully?
> > 2b) if yes, can we guarantee there are no broken configurations in the wild?
> > 
> > Depending on the answers correct your code and/or commit message.

The above is a list of the questions you need to investigate.
(Note, it takes several minutes on elixir.bootlin.com to check
 some of this, but I'm not the author of the code)

> >> Otherwise you have to _justify_ that this functional change won't break
> >> existing setups (with broked IRQ in Device Tree, for example).
> 
> Sorry, I do not quite understand what you mean.
> I have no idea how these questions are related to my patch.

The IRQ is usually provided by Device Tree or ACPI (here is DT only case).
Then the platform code converts that to resource which this driver consumes.
That resource is used when instantiating GPIO (IRQ) chip.

> Do you mean I should not fail the ->probe() if there is wrong IRQ numbering in the DT?

I don't know. The commit message of your change should elaborate this.

> Please tell me the relationship between these questions and my patch.

The tight relationship. The patch changes the flow. Either
you shouldn't do that, or be aware and explain why it's not
a problem. Or get it done differently.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-06-07 14:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06  3:18 [PATCH v3] gpio: ath79: Add missing check for platform_get_irq Jiasheng Jiang
2023-06-06  9:28 ` andy.shevchenko
2023-06-06  9:46   ` andy.shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2023-06-07  7:08 Jiasheng Jiang
2023-06-07 14:49 ` andy.shevchenko
2023-06-05  1:53 Jiasheng Jiang
2023-06-05  9:20 ` Andy Shevchenko

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).