Skip to content

fix fwnode_irq_get_byname() returnvalue

Matti Vaittinen linux-acpi linux-i2c linux-iio lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 4 repliesIn review
  2. v22 patches 4 repliesSuperseded
  3. v12 patches 6 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3drivers: fwnode: fix fwnode_irq_get_byname()drivers/base/property.c+7 -22 replies
2/3i2c: i2c-smbus: fwnode_irq_get_byname() return value fixdrivers/i2c/i2c-smbus.c+1 -10 replies
3/3iio: kx022a fix irq gettingdrivers/iio/accel/kionix-kx022a.c+1 -12 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchSakari AilusAndy Shevchenko
1/3R-b R-b
2/3R-b R-b
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] fix fwnode_irq_get_byname() returnvalue

The fix fwnode_irq_get_byname() may have returned zero if mapping the IRQ fails. This contradicts the 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_byname() to always return a negative errno upon failure. I have also audited following callers (v6.4-rc1):

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

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.

---

Matti Vaittinen (3):
drivers: fwnode: fix fwnode_irq_get_byname()
i2c: i2c-smbus: fwnode_irq_get_byname() return value fix
iio: kx022a fix irq getting

 drivers/base/property.c           | 9 +++++++--
 drivers/i2c/i2c-smbus.c           | 2 +-
 drivers/iio/accel/kionix-kx022a.c | 2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

base-commit: ac9a78681b921877518763ba0e89202254349d1b

Signature · 14 lines
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 =]