linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 0/9] fix fwnode_irq_get[_byname()] returnvalue
@ 2023-05-29  6:22 Matti Vaittinen
  2023-05-29  6:22 ` [PATCH v7 1/9] drivers: fwnode: fix fwnode_irq_get[_byname]() Matti Vaittinen
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Matti Vaittinen @ 2023-05-29  6:22 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Wolfram Sang,
	Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Andreas Klinger, Marcin Wojtas, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Jonathan Neuschäfer, Linus Walleij, Paul Cercueil, Akhil R,
	linux-acpi, linux-kernel, linux-i2c, linux-iio, netdev, openbmc,
	linux-gpio, linux-mips

[-- Attachment #1: Type: text/plain, Size: 4497 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.

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
Changed logic so that all the IRQ getting errors jump to the same
'no-IRQ' branch as the DT mapping error did.

Revision history:
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 (9):
  drivers: fwnode: fix fwnode_irq_get[_byname]()
  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/base/property.c                         | 12 +++++++++---
 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 ------
 8 files changed, 23 insertions(+), 30 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 =] 

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

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

end of thread, other threads:[~2023-06-16 11:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-29  6:22 [PATCH v7 0/9] fix fwnode_irq_get[_byname()] returnvalue Matti Vaittinen
2023-05-29  6:22 ` [PATCH v7 1/9] drivers: fwnode: fix fwnode_irq_get[_byname]() Matti Vaittinen
2023-05-29  6:22 ` [PATCH v7 2/9] iio: mb1232: relax return value check for IRQ get Matti Vaittinen
2023-05-29  6:23 ` [PATCH v7 3/9] iio: cdc: ad7150: " Matti Vaittinen
2023-05-29  6:23 ` [PATCH v7 4/9] pinctrl: wpcm450: " Matti Vaittinen
2023-05-29  6:23 ` [PATCH v7 5/9] pinctrl: ingenic: " Matti Vaittinen
2023-05-29  6:23 ` [PATCH v7 6/9] pinctrl: pistachio: " Matti Vaittinen
2023-05-29  6:24 ` [PATCH v7 7/9] i2c: i2c-smbus: fwnode_irq_get_byname() return value fix Matti Vaittinen
2023-05-29  6:24 ` [PATCH v7 8/9] net-next: mvpp2: relax return value check for IRQ get Matti Vaittinen
2023-05-29  6:25 ` [PATCH v7 9/9] net-next: mvpp2: don't shadow error Matti Vaittinen
2023-05-31  6:34 ` [PATCH v7 0/9] fix fwnode_irq_get[_byname()] returnvalue Jakub Kicinski
2023-06-15 11:37   ` Greg Kroah-Hartman
2023-06-16  2:28     ` Jakub Kicinski
2023-06-16 11:45     ` Matti Vaittinen

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