2023-05-16 07:42:26

by Matti Vaittinen

[permalink] [raw]
Subject: [PATCH v4 0/7] fix fwnode_irq_get[_byname()] returnvalue

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.

Here we change the fwnode_irq_get() and the fwnode_irq_get_byname() to
always return a negative errno upon failure.

I have audited following callers (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 the change. 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
will gain functional change as well. Here the logic is less
straightforward but boils down to the same question as with the
pinctrl-wpcm450.c. Should all the IRQ getting errors jump to same
'no-IRQ' branch as the DT mapping error, or should the DT mapping error
abort the probe with error same way as other IRQ getting failures do?

Revision history:
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 (7):
drivers: fwnode: fix fwnode_irq_get[_byname]()
iio: mb1232: relax return value check for IRQ get
net-next: mb1232: relax return value check for IRQ get
pinctrl: wpcm450: elax return value check for IRQ get
pinctrl: ingenic: relax return value check for IRQ get
pinctrl: pistachio: relax return value check for IRQ get
iio: cdc: ad7150: Functional change

drivers/base/property.c | 12 +++++++++---
drivers/iio/cdc/ad7150.c | 3 +--
drivers/iio/proximity/mb1232.c | 4 ++--
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 ++--
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c | 2 --
drivers/pinctrl/pinctrl-ingenic.c | 2 --
drivers/pinctrl/pinctrl-pistachio.c | 6 ------
7 files changed, 14 insertions(+), 19 deletions(-)


base-commit: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6
--
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 =]


Attachments:
(No filename) (4.04 kB)
signature.asc (499.00 B)
Download all attachments

2023-05-16 07:45:32

by Matti Vaittinen

[permalink] [raw]
Subject: [PATCH v4 3/7] net-next: mb1232: relax return value check for IRQ get

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

Drop check for return value 0.

Signed-off-by: Matti Vaittinen <[email protected]>

---

The first patch of the series changes the fwnode_irq_get() so this depends
on the first patch of the series and should not be applied alone.
---
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 adc953611913..5b987af306a5 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 =]


Attachments:
(No filename) (1.55 kB)
signature.asc (499.00 B)
Download all attachments

2023-05-17 13:09:59

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v4 0/7] fix fwnode_irq_get[_byname()] returnvalue

On Tue, May 16, 2023 at 9:12 AM Matti Vaittinen
<[email protected]> wrote:

> 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:

Also, zero is not really a valid IRQ, it means NO_IRQ:
https://lwn.net/Articles/470820/

I'll apply the pinctrl patches.

Yours,
Linus Walleij

2023-05-17 13:23:05

by Matti Vaittinen

[permalink] [raw]
Subject: Re: [PATCH v4 0/7] fix fwnode_irq_get[_byname()] returnvalue

On 5/17/23 15:43, Linus Walleij wrote:
> On Tue, May 16, 2023 at 9:12 AM Matti Vaittinen
> <[email protected]> wrote:
>
>> 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:
>
> Also, zero is not really a valid IRQ, it means NO_IRQ:
> https://lwn.net/Articles/470820/
>
> I'll apply the pinctrl patches.

Thanks Linus. I guess you noticed but please wait until the patch 1/7
gets in as the pinctrl patches won't do "the right thing" without it.
(Just ensuring we are on a same page ;) )

Yours,
-- Matti

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

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