public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] fix fwnode_irq_get_byname() returnvalue
@ 2022-10-25 15:11 Matti Vaittinen
  2022-10-25 15:11 ` [PATCH v2 1/2] drivers: fwnode: fix fwnode_irq_get_byname() Matti Vaittinen
  2022-10-25 15:12 ` [PATCH v2 2/2] i2c: i2c-smbus: fwnode_irq_get_byname() return value fix Matti Vaittinen
  0 siblings, 2 replies; 7+ messages in thread
From: Matti Vaittinen @ 2022-10-25 15:11 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, Akhil R,
	linux-acpi, linux-kernel, linux-i2c

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

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:

drivers/i2c/i2c-smbus.c
drivers/iio/accel/adxl355_core.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 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.

Changelog v1 => v2:
 - minor styling

---

Matti Vaittinen (2):
  drivers: fwnode: fix fwnode_irq_get_byname()
  i2c: i2c-smbus: fwnode_irq_get_byname() return value fix

 drivers/base/property.c | 9 +++++++--
 drivers/i2c/i2c-smbus.c | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)


base-commit: 247f34f7b80357943234f93f247a1ae6b6c3a740
-- 
2.37.3


-- 
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] 7+ messages in thread

end of thread, other threads:[~2022-11-15  9:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-25 15:11 [PATCH v2 0/2] fix fwnode_irq_get_byname() returnvalue Matti Vaittinen
2022-10-25 15:11 ` [PATCH v2 1/2] drivers: fwnode: fix fwnode_irq_get_byname() Matti Vaittinen
2022-10-25 16:21   ` Andy Shevchenko
2022-10-25 15:12 ` [PATCH v2 2/2] i2c: i2c-smbus: fwnode_irq_get_byname() return value fix Matti Vaittinen
2022-10-25 16:30   ` Andy Shevchenko
2022-10-27  5:40     ` Vaittinen, Matti
2022-11-15  9:09       ` Vaittinen, Matti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox