netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/8] fix fwnode_irq_get[_byname()] returnvalue
@ 2023-08-01 12:00 Matti Vaittinen
  2023-08-01 12:04 ` [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get Matti Vaittinen
  2023-08-01 12:04 ` [PATCH v8 8/8] net-next: mvpp2: don't shadow error Matti Vaittinen
  0 siblings, 2 replies; 6+ messages in thread
From: Matti Vaittinen @ 2023-08-01 12:00 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Marcin Wojtas, netdev, Andreas Klinger, Jonathan Neuschäfer,
	openbmc, linux-mips, Jonathan Cameron, David S. Miller,
	Paul Cercueil, Lars-Peter Clausen, linux-gpio, linux-iio,
	Russell King, linux-kernel, Wolfram Sang, Eric Dumazet, linux-i2c,
	Jakub Kicinski, Michael Hennerich, Linus Walleij, Paolo Abeni

[-- Attachment #1: Type: text/plain, Size: 4627 bytes --]

The fwnode_irq_get() and the fwnode_irq_get_byname() may have returned
zero if mapping the IRQ fails. This contradicts the
fwnode_irq_get_byname() documentation. Furthermore, returning zero or
errno on error is unepected and can easily lead to problems
like:

int probe(foo)
{
...
	ret = fwnode_irq_get_byname(...);
	if (ret < 0)
		return ret;
...
}

or

int probe(foo)
{
...
	ret = fwnode_irq_get_byname(...);
	if (ret <= 0)
		return ret;
...
}

which are both likely to be wrong. First treats zero as successful call and
misses the IRQ mapping failure. Second returns zero from probe even though
it detects the IRQ mapping failure correvtly.

Thus the fwnode_irq_get() and the fwnode_irq_get_byname() were changed to
always return a negative errno upon failure.

https://lore.kernel.org/all/fb7241d3-d1d1-1c37-919b-488d6d007484@gmail.com/

This is a clean-up patch to adjust callers. Please note that callers
were audited based on v6.4-rc2:

fwnode_irq_get_byname():
drivers/i2c/i2c-smbus.c
drivers/iio/accel/adxl355_core.c
drivers/iio/accel/kionix-kx022a.c
drivers/iio/adc/ad4130.c
drivers/iio/adc/max11410.c
drivers/iio/addac/ad74115.c
drivers/iio/gyro/fxas21002c_core.c
drivers/iio/imu/adis16480.c
drivers/iio/imu/bmi160/bmi160_core.c
drivers/iio/imu/bmi160/bmi160_core.c

fwnode_irq_get():
drivers/gpio/gpio-dwapb.c
drivers/iio/chemical/scd30_serial.c
drivers/iio/proximity/mb1232.c
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
drivers/net/mdio/fwnode_mdio.c
drivers/pinctrl/pinctrl-ingenic.c
drivers/pinctrl/pinctrl-microchip-sgpio.c
drivers/pinctrl/pinctrl-pistachio.c

and it seems to me these calls will be Ok after this clean-up. The
i2c-smbus.c and kionix-kx022a.c will gain a functional change (bugfix?) as
after this patch the probe will return -EINVAL should the IRQ mapping fail.
The series will also adjust the return value check for zero to be omitted.

NOTES:

Changes are compile-tested only.

drivers/pinctrl/nuvoton/pinctrl-wpcm450.c
will also gain a functional change. The pinctrl-wpcm450.c change is easy
to see - after this series the device-tree mapping failures will be
handled as any other errors - probe will be aborted with -EINVAL. Other
feasible option could be treating other errors in IRQ getting same way
as the DT mapping failures - just silently skip the IRQ. Please see
comment in the respective patch.

drivers/iio/cdc/ad7150.c
Changed logic so that all the IRQ getting errors jump to the same
'no-IRQ' branch as the DT mapping error did.

Revision history:
v7 => v8:
 - drop ptach 1/N which was merged during 6.4 development.
 - rebase on top of the v6.5-rc4.
v6 => v7:
 - re-ordered patches per subsystem
 - mvpp2 - added a patch for not shadowing the return value
v5 => v6:
 - iio: cdc: ad7150 - never abort probe if IRQ getting fails
v4 => v5:
 - Fix subject lines for mvpp2 and wpcm450
 - drop unnecessary irqno assignment from mb1232
 - add back the drivers/i2c/i2c-smbus.c change which was accidentally
   dropped during v3 => v4 work
v3 => v4:
 - Change also the fwnode_irq_get() as was suggested by Jonathan.
Changelog v2 => v3:
 - rebase/resend/add kx022a fix.
Changelog v1 => v2:
 - minor styling

---

Matti Vaittinen (8):
  iio: mb1232: relax return value check for IRQ get
  iio: cdc: ad7150: relax return value check for IRQ get
  pinctrl: wpcm450: relax return value check for IRQ get
  pinctrl: ingenic: relax return value check for IRQ get
  pinctrl: pistachio: relax return value check for IRQ get
  i2c: i2c-smbus: fwnode_irq_get_byname() return value fix
  net-next: mvpp2: relax return value check for IRQ get
  net-next: mvpp2: don't shadow error

 drivers/i2c/i2c-smbus.c                         |  2 +-
 drivers/iio/cdc/ad7150.c                        | 10 +++++-----
 drivers/iio/proximity/mb1232.c                  |  7 ++-----
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 12 ++++++------
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c       |  2 --
 drivers/pinctrl/pinctrl-ingenic.c               |  2 --
 drivers/pinctrl/pinctrl-pistachio.c             |  6 ------
 7 files changed, 14 insertions(+), 27 deletions(-)


base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4
-- 
2.40.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get
  2023-08-01 12:00 [PATCH v8 0/8] fix fwnode_irq_get[_byname()] returnvalue Matti Vaittinen
@ 2023-08-01 12:04 ` Matti Vaittinen
  2023-08-01 12:31   ` Russell King (Oracle)
  2023-08-01 12:04 ` [PATCH v8 8/8] net-next: mvpp2: don't shadow error Matti Vaittinen
  1 sibling, 1 reply; 6+ messages in thread
From: Matti Vaittinen @ 2023-08-01 12:04 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Marcin Wojtas, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1701 bytes --]

fwnode_irq_get[_byname]() were changed to not return 0 anymore.

Drop check for return value 0.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>

---
Revision history:
v5 =>:
 - No changes
v4 = v5:
Fix the subject, mb1232 => mvpp2

The patch changing the fwnode_irq_get() got merged during 5.4:
https://lore.kernel.org/all/fb7241d3-d1d1-1c37-919b-488d6d007484@gmail.com/
This is a clean-up as agreed.
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 1fec84b4c068..2632ffe91ca5 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -5833,7 +5833,7 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
 			v->irq = of_irq_get_byname(port_node, irqname);
 		else
 			v->irq = fwnode_irq_get(port->fwnode, i);
-		if (v->irq <= 0) {
+		if (v->irq < 0) {
 			ret = -EINVAL;
 			goto err;
 		}
@@ -6764,7 +6764,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 		err = -EPROBE_DEFER;
 		goto err_deinit_qvecs;
 	}
-	if (port->port_irq <= 0)
+	if (port->port_irq < 0)
 		/* the link irq is optional */
 		port->port_irq = 0;
 
-- 
2.40.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v8 8/8] net-next: mvpp2: don't shadow error
  2023-08-01 12:00 [PATCH v8 0/8] fix fwnode_irq_get[_byname()] returnvalue Matti Vaittinen
  2023-08-01 12:04 ` [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get Matti Vaittinen
@ 2023-08-01 12:04 ` Matti Vaittinen
  2023-08-01 12:31   ` Russell King (Oracle)
  1 sibling, 1 reply; 6+ messages in thread
From: Matti Vaittinen @ 2023-08-01 12:04 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Marcin Wojtas, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1522 bytes --]

Do not overwrite error from lower layers but return the actual error to
user if obtaining an IRQ fails.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 2632ffe91ca5..2aba34a2ca76 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -5830,13 +5830,13 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
 		}
 
 		if (port_node)
-			v->irq = of_irq_get_byname(port_node, irqname);
+			ret = of_irq_get_byname(port_node, irqname);
 		else
-			v->irq = fwnode_irq_get(port->fwnode, i);
-		if (v->irq < 0) {
-			ret = -EINVAL;
+			ret = fwnode_irq_get(port->fwnode, i);
+		if (ret < 0)
 			goto err;
-		}
+
+		v->irq = ret;
 
 		netif_napi_add(port->dev, &v->napi, mvpp2_poll);
 	}
-- 
2.40.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get
  2023-08-01 12:04 ` [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get Matti Vaittinen
@ 2023-08-01 12:31   ` Russell King (Oracle)
  2023-08-01 12:44     ` Matti Vaittinen
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King (Oracle) @ 2023-08-01 12:31 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Matti Vaittinen, Marcin Wojtas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On Tue, Aug 01, 2023 at 03:04:24PM +0300, Matti Vaittinen wrote:
> fwnode_irq_get[_byname]() were changed to not return 0 anymore.
> 
> Drop check for return value 0.
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>

Sorry, but I don't think you've properly considered the effects of your
patch.

> @@ -5833,7 +5833,7 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
>  			v->irq = of_irq_get_byname(port_node, irqname);
>  		else
>  			v->irq = fwnode_irq_get(port->fwnode, i);
> -		if (v->irq <= 0) {
> +		if (v->irq < 0) {

You're making this change based on the assumption that fwnode_irq_get()
has changed its return values, but I really don't think you've looked
at the code and considered the return value behaviour of the DT function
above. Reading it's documentation, it states that of_irq_get_byname()
may return 0 on IRQ mapping failure.

So, by making this change, you are allowing IRQ mapping failure in the
DT path to succeed rather than fail.

>  			ret = -EINVAL;
>  			goto err;
>  		}
> @@ -6764,7 +6764,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
>  		err = -EPROBE_DEFER;
>  		goto err_deinit_qvecs;
>  	}
> -	if (port->port_irq <= 0)
> +	if (port->port_irq < 0)

Exactly the same problem here, but...

>  		/* the link irq is optional */
>  		port->port_irq = 0;

this is less critical... but still wrong.

So, given that this patch is basically incorrect...

NAK.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH v8 8/8] net-next: mvpp2: don't shadow error
  2023-08-01 12:04 ` [PATCH v8 8/8] net-next: mvpp2: don't shadow error Matti Vaittinen
@ 2023-08-01 12:31   ` Russell King (Oracle)
  0 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2023-08-01 12:31 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Matti Vaittinen, Marcin Wojtas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On Tue, Aug 01, 2023 at 03:04:40PM +0300, Matti Vaittinen wrote:
> Do not overwrite error from lower layers but return the actual error to
> user if obtaining an IRQ fails.
> 
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>

Since your previous patch is incorrect, this one is too.

NAK.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get
  2023-08-01 12:31   ` Russell King (Oracle)
@ 2023-08-01 12:44     ` Matti Vaittinen
  0 siblings, 0 replies; 6+ messages in thread
From: Matti Vaittinen @ 2023-08-01 12:44 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Matti Vaittinen, Marcin Wojtas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On 8/1/23 15:31, Russell King (Oracle) wrote:
> On Tue, Aug 01, 2023 at 03:04:24PM +0300, Matti Vaittinen wrote:
>> fwnode_irq_get[_byname]() were changed to not return 0 anymore.
>>
>> Drop check for return value 0.
>>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> 
> Sorry, but I don't think you've properly considered the effects of your
> patch.

Don't be sorry.

> 
>> @@ -5833,7 +5833,7 @@ static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port,
>>   			v->irq = of_irq_get_byname(port_node, irqname);
>>   		else
>>   			v->irq = fwnode_irq_get(port->fwnode, i);
>> -		if (v->irq <= 0) {
>> +		if (v->irq < 0) {
> 
> You're making this change based on the assumption that fwnode_irq_get()
> has changed its return values, but I really don't think you've looked
> at the code and considered the return value behaviour of the DT function
> above. Reading it's documentation, it states that of_irq_get_byname()
> may return 0 on IRQ mapping failure.

You're correct. Thanks for spotting this! Seems like I really overlooked 
the behaviour of the of_irq_get_byname().

> So, by making this change, you are allowing IRQ mapping failure in the
> DT path to succeed rather than fail.
> 
>>   			ret = -EINVAL;
>>   			goto err;
>>   		}
>> @@ -6764,7 +6764,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
>>   		err = -EPROBE_DEFER;
>>   		goto err_deinit_qvecs;
>>   	}
>> -	if (port->port_irq <= 0)
>> +	if (port->port_irq < 0)
> 
> Exactly the same problem here, but...
> 
>>   		/* the link irq is optional */
>>   		port->port_irq = 0;
> 
> this is less critical... but still wrong.
> 
> So, given that this patch is basically incorrect...
> 
> NAK.
> 

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


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

end of thread, other threads:[~2023-08-01 12:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-01 12:00 [PATCH v8 0/8] fix fwnode_irq_get[_byname()] returnvalue Matti Vaittinen
2023-08-01 12:04 ` [PATCH v8 7/8] net-next: mvpp2: relax return value check for IRQ get Matti Vaittinen
2023-08-01 12:31   ` Russell King (Oracle)
2023-08-01 12:44     ` Matti Vaittinen
2023-08-01 12:04 ` [PATCH v8 8/8] net-next: mvpp2: don't shadow error Matti Vaittinen
2023-08-01 12:31   ` Russell King (Oracle)

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