fix fwnode_irq_get[_byname()] returnvalue
Subsystems (16)
v5 cover 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.cdrivers/iio/accel/adxl355_core.cdrivers/iio/accel/kionix-kx022a.cdrivers/iio/adc/ad4130.cdrivers/iio/adc/max11410.cdrivers/iio/addac/ad74115.cdrivers/iio/gyro/fxas21002c_core.cdrivers/iio/imu/adis16480.cdrivers/iio/imu/bmi160/bmi160_core.cdrivers/iio/imu/bmi160/bmi160_core.c
fwnode_irq_get():drivers/gpio/gpio-dwapb.cdrivers/iio/chemical/scd30_serial.cdrivers/iio/proximity/mb1232.cdrivers/net/ethernet/marvell/mvpp2/mvpp2_main.cdrivers/net/mdio/fwnode_mdio.cdrivers/pinctrl/pinctrl-ingenic.cdrivers/pinctrl/pinctrl-microchip-sgpio.cdrivers/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:
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):
drivers: fwnode: fix fwnode_irq_get[_byname]()
iio: mb1232: relax return value check for IRQ get
net-next: mvpp2: 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
iio: cdc: ad7150: Functional change
i2c: i2c-smbus: fwnode_irq_get_byname() return value fix
drivers/base/property.c | 12 +++++++++--- drivers/i2c/i2c-smbus.c | 2 +- drivers/iio/cdc/ad7150.c | 3 +-- drivers/iio/proximity/mb1232.c | 7 ++----- 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 ------ 8 files changed, 15 insertions(+), 23 deletions(-)
base-commit: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6
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 =]
PATCH v5 1/8 drivers: fwnode: fix fwnode_irq_get[_byname]()
The fwnode_irq_get() and the fwnode_irq_get_byname() return 0 upon device-tree IRQ mapping failure. This is contradicting the fwnode_irq_get_byname() function documentation and can potentially be a source of errors like:
int probe(...) {
...
irq = fwnode_irq_get_byname();
if (irq <= 0)
return irq;
...
}Here we do correctly check the return value from fwnode_irq_get_byname() but the driver probe will now return success. (There was already one such user in-tree).
Change the fwnode_irq_get_byname() to work as documented and make also the fwnode_irq_get() follow same common convention returning a negative errno upon failure.
---
I dropped the existing reviewed-by tags because change to fwnode_irq_get() was added.
Revision history:
v3 => v4:
- Change also the fwnode_irq_get()
--- drivers/base/property.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/base/property.c +9 -3
@@ -987,12 +987,18 @@ EXPORT_SYMBOL(fwnode_iomap);* @fwnode: Pointer to the firmware node * @index: Zero-based index of the IRQ * -* Return: Linux IRQ number on success. Other values are determined -* according to acpi_irq_get() or of_irq_get() operation. +* Return: Linux IRQ number on success. Negative errno on failure. */ int fwnode_irq_get (const struct fwnode_handle *fwnode,unsigned int index) { -return fwnode_call_int_op (fwnode, irq_get, index); +int ret; + + ret =fwnode_call_int_op (fwnode, irq_get, index); +/* We treat mapping errors as invalid case */ +if (ret ==0 ) +return -EINVAL ; + +return ret; }EXPORT_SYMBOL (fwnode_irq_get);
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 =]
PATCH v5 2/8 iio: mb1232: relax return value check for IRQ get
In reply to Matti Vaittinenfwnode_irq_get() was changed to not return 0 anymore.
Drop check for return value 0.
---
Revsion history:
v4 => v5:
- drop unnecessary data->irqnr = -1 assignment
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/iio/proximity/mb1232.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/proximity/mb1232.c +2 -5
@@ -76,7 +76,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data) goto error_unlock; } -if (data->irqnr >=0 ) { +if (data->irqnr >0 ) {/* it cannot take more than 100 ms */ ret =wait_for_completion_killable_timeout (&data->ranging,HZ /10 );
@@ -212,10 +212,7 @@ static int mb1232_probe(struct i2c_client *client)init_completion (&data->ranging); data->irqnr =fwnode_irq_get (dev_fwnode (&client->dev),0 ); -if (data->irqnr <=0 ) { -/* usage of interrupt is optional */ - data->irqnr =-1 ; - }else { +if (data->irqnr >0 ) { ret =devm_request_irq (dev, data->irqnr, mb1232_handle_irq,IRQF_TRIGGER_FALLING , id->name, indio_dev);if (ret <0 ) {
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 =]
PATCH v5 3/8 net-next: mvpp2: relax return value check for IRQ get
In reply to Matti Vaittinenfwnode_irq_get[_byname]() were changed to not return 0 anymore.
Drop check for return value 0.
---
Revision history:
v4 = v5:
Fix the subject, mb1232 => mvpp2
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(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +2 -2
@@ -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 ;
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 =]
PATCH v5 4/8 pinctrl: wpcm450: relax return value check for IRQ get
In reply to Matti Vaittinenfwnode_irq_get[_byname]() were changed to not return 0 anymore. The special error case where device-tree based IRQ mapping fails can't no longer be reliably detected from this return value. This yields a functional change in the driver where the mapping failure is treated as an error.
The mapping failure can occur for example when the device-tree IRQ information translation call-back(s) (xlate) fail, IRQ domain is not found, IRQ type conflicts, etc. In most cases this indicates an error in the device-tree and special handling is not really required.
One more thing to note is that ACPI APIs do not return zero for any failures so this special handling did only apply on device-tree based systems.
Drop the special (no error, just skip the IRQ) handling for DT mapping failures as these can no longer be separated from other errors at driver side.
---
Revision history:
v4 => v5:
Fix typo in subject "elax" => "relax"
Please note, I took Linus' reply to v4 cover-letter as ack && added the tag. Please let me know if this was not Ok.
The special handling in this driver was added when fixing a problem where returning zero from fwnode_irq_get[_byname]() was treated as succes yielding zero being used as a valid IRQ by the driver. f4a31facfa80 ("pinctrl: wpcm450: Correct the fwnode_irq_get() return value check") The commit message does not mention if choosing not to abort the probe on device-tree mapping failure (as is done on other errors) was chosen
because: a) Abort would have broken some existing setup. b) Because skipping an IRQ on failure is "the right thing to do", or c) because it sounded like a way to minimize risk of breaking something.
If the reason is a) - then I'd appreciate receiving some more information and a suggestion how to proceed (if possible). If the reason is b), then it might be best to just skip the IRQ instead of aborting the probe for all errors on IRQ getting. Finally, in case of c), well, by acking this change you will now accept the risk :)
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/pinctrl/nuvoton/pinctrl-wpcm450.c | 2 -- 1 file changed, 2 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +0 -2
@@ -1106,8 +1106,6 @@ static int wpcm450_gpio_register(struct platform_device *pdev, irq =fwnode_irq_get (child, i);if (irq <0 )break ; -if (!irq) -continue ; girq->parents[i] = irq; girq->num_parents++;
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 =]
PATCH v5 5/8 pinctrl: ingenic: relax return value check for IRQ get
In reply to Matti Vaittinenfwnode_irq_get[_byname]() were changed to not return 0 anymore.
Drop check for return value 0.
---
Please note, I took Linus' reply to v4 cover-letter as ack && added the tag. Please let me know if this was not Ok.
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/pinctrl/pinctrl-ingenic.c | 2 -- 1 file changed, 2 deletions(-)
drivers/pinctrl/pinctrl-ingenic.c +0 -2
@@ -4201,8 +4201,6 @@ static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc, err =fwnode_irq_get (fwnode,0 );if (err <0 )return err; -if (!err) -return -EINVAL ; jzgc->irq = err; girq = &jzgc->gc.irq;
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 =]
PATCH v5 6/8 pinctrl: pistachio: relax return value check for IRQ get
In reply to Matti Vaittinenfwnode_irq_get[_byname]() were changed to not return 0 anymore.
Drop check for return value 0.
---
Please note, I took Linus' reply to v4 cover-letter as ack && added the tag. Please let me know if this was not Ok.
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/pinctrl/pinctrl-pistachio.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/pinctrl/pinctrl-pistachio.c +0 -6
@@ -1393,12 +1393,6 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)dev_err (pctl->dev,"Failed to retrieve IRQ for bank %u\n" , i); goto err; } -if (!ret) { -fwnode_handle_put (child); -dev_err (pctl->dev,"No IRQ for bank %u\n" , i); - ret = -EINVAL ; - goto err; - } irq = ret; bank = &pctl->gpio_banks[i];
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 =]
PATCH v5 7/8 iio: cdc: ad7150: relax return value check for IRQ get
In reply to Matti Vaittinenfwnode_irq_get[_byname]() were changed to not return 0 anymore. The special error case where device-tree based IRQ mapping fails can't no longer be reliably detected from this return value. This yields a functional change in the driver where the mapping failure is treated as an error.
The mapping failure can occur for example when the device-tree IRQ information translation call-back(s) (xlate) fail, IRQ domain is not found, IRQ type conflicts, etc. In most cases this indicates an error in the device-tree and special handling is not really required.
One more thing to note is that ACPI APIs do not return zero for any failures so this special handling did only apply on device-tree based systems.
Drop the special handling for DT mapping failures as these can no longer be separated from other errors at driver side.
---
Please note that I don't have the hardware to test this change. Furthermore, testing this type of device-tree error cases is not trivial, as the question we probably dive in is "what happens with the existing users who have errors in the device-tree". Answering to this question is not simple.
I did this patch with minimal code changes - but a question is if we should really jump into the else branch below on all IRQ getting errors?
} else {
indio_dev->info = &ad7150_info_no_irq;
switch (id->driver_data) {
case AD7150:
indio_dev->channels = ad7150_channels_no_irq;
indio_dev->num_channels =
ARRAY_SIZE(ad7150_channels_no_irq);
break;
case AD7151:
indio_dev->channels = ad7151_channels_no_irq;
indio_dev->num_channels =
ARRAY_SIZE(ad7151_channels_no_irq);
break;
default:
return -EINVAL;
}Why do we have special handling for !chip->interrupts[0] while other errors on getting the fwnode_irq_get(dev_fwnode(&client->dev), 0); will abort the probe?
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/iio/cdc/ad7150.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/cdc/ad7150.c +1 -2
@@ -567,8 +567,7 @@ static int ad7150_probe(struct i2c_client *client)if (chip->interrupts[1 ] <0 )return chip->interrupts[1 ]; } -if (chip->interrupts[0 ] && - (id->driver_data ==AD7151 || chip->interrupts[1 ])) { +if (id->driver_data ==AD7151 || chip->interrupts[1 ]) {irq_set_status_flags (chip->interrupts[0 ],IRQ_NOAUTOEN ); ret = devm_request_threaded_irq(&client->dev, chip->interrupts[0],
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 =]
PATCH v5 8/8 i2c: i2c-smbus: fwnode_irq_get_byname() return value fix
In reply to Matti VaittinenThe fwnode_irq_get_byname() was changed to not return 0 upon failure so return value check can be adjusted to reflect the change.
---
Revision history:
v4 => v5:
- Added back after this was accidentally dropped at v4.
Depends on the mentioned return value change which is in patch 1/2. The return value change does also cause a functional change here. Eg. when IRQ mapping fails, the fwnode_irq_get_byname() no longer returns zero. This will cause also the probe here to return nonzero failure. I guess this is desired behaviour - but I would appreciate any confirmation.
Please, see also previous discussion here:
https://lore.kernel.org/all/fbd52f5f5253b382b8d7b3e8046134de29f965b8.1666710197.git.mazziesaccount@gmail.com/
Another suggestion has been to drop the check altogether. I am slightly reluctant on doing that unless it gets confirmed that is the "right thing to do".
--- drivers/i2c/i2c-smbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-smbus.c +1 -1
@@ -129,7 +129,7 @@ static int smbalert_probe(struct i2c_client *ara) }else { irq =fwnode_irq_get_byname (dev_fwnode (adapter->dev.parent),"smbus_alert" ); -if (irq <=0 ) +if (irq <0 )return irq; }
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 =]
Jonathan Cameron
maintainerRe: [PATCH v5 7/8] iio: cdc: ad7150: relax return value check for IRQ get
In reply to Matti VaittinenQuoted 48 lines · On Fri, 19 May 2023 14:04:32 +0300 Matti Vaittinen <[email protected]>…
fwnode_irq_get[_byname]() were changed to not return 0 anymore. The special error case where device-tree based IRQ mapping fails can't no longer be reliably detected from this return value. This yields a functional change in the driver where the mapping failure is treated as an error.
The mapping failure can occur for example when the device-tree IRQ information translation call-back(s) (xlate) fail, IRQ domain is not found, IRQ type conflicts, etc. In most cases this indicates an error in the device-tree and special handling is not really required.
One more thing to note is that ACPI APIs do not return zero for any failures so this special handling did only apply on device-tree based systems.
Drop the special handling for DT mapping failures as these can no longer be separated from other errors at driver side.
Signed-off-by Matti Vaittinen <[email protected]>---
Please note that I don't have the hardware to test this change. Furthermore, testing this type of device-tree error cases is not trivial, as the question we probably dive in is "what happens with the existing users who have errors in the device-tree". Answering to this question is not simple.
I did this patch with minimal code changes - but a question is if we should really jump into the else branch below on all IRQ getting errors?
} else { indio_dev->info = &ad7150_info_no_irq; switch (id->driver_data) { case AD7150: indio_dev->channels = ad7150_channels_no_irq; indio_dev->num_channels = ARRAY_SIZE(ad7150_channels_no_irq); break; case AD7151: indio_dev->channels = ad7151_channels_no_irq; indio_dev->num_channels = ARRAY_SIZE(ad7151_channels_no_irq); break; default: return -EINVAL; }
Quoted 3 lines
Why do we have special handling for !chip->interrupts[0] while other errors on getting the
fwnode_irq_get(dev_fwnode(&client->dev), 0); will abort the probe?
Gut feeling is that this was a rework of board file code where 0 meant not provided. We should look to do the same here. I'm not sure we have a consistent return for no irq though across the various fw types.
The driver looks like it should support either no interrupts or all the ones for a given device.
Currrently it definitely doesn't handle the no irqs provided case right. Its not elegant, but if we have to have all failures to get irqs result in carrying on without them then that's better than now.
Jonathan
Quoted 21 lines
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/iio/cdc/ad7150.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/iio/cdc/ad7150.c +1
-2@@ -567,8 +567,7 @@ static int ad7150_probe(struct i2c_client *client)if (chip->interrupts[1 ] <0 )return chip->interrupts[1 ]; } -if (chip->interrupts[0 ] && - (id->driver_data ==AD7151 || chip->interrupts[1 ])) { +if (id->driver_data ==AD7151 || chip->interrupts[1 ]) {irq_set_status_flags (chip->interrupts[0 ],IRQ_NOAUTOEN ); ret = devm_request_threaded_irq(&client->dev, chip->interrupts[0],
Re: [PATCH v5 2/8] iio: mb1232: relax return value check for IRQ get
In reply to Matti VaittinenQuoted 6 lines · On Fri, 19 May 2023 14:01:23 +0300 Matti Vaittinen <[email protected]>…
fwnode_irq_get()was changed to not return 0 anymore.Drop check for return value 0.
Signed-off-by Matti Vaittinen <[email protected]>
Quoted 36 lines
---
Revsion history:
v4 => v5:
- drop unnecessarydata->irqnr= -1 assignmentThe 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/iio/proximity/mb1232.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/iio/proximity/mb1232.c +2
-5@@ -76,7 +76,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data) goto error_unlock; } -if (data->irqnr >=0 ) { +if (data->irqnr >0 ) {/* it cannot take more than 100 ms */ ret =wait_for_completion_killable_timeout (&data->ranging,HZ /10 );@@ -212,10 +212,7 @@ static int mb1232_probe(struct i2c_client *client)init_completion (&data->ranging); data->irqnr =fwnode_irq_get (dev_fwnode (&client->dev),0 ); -if (data->irqnr <=0 ) { -/* usage of interrupt is optional */ - data->irqnr =-1 ; - }else { +if (data->irqnr >0 ) { ret =devm_request_irq (dev, data->irqnr, mb1232_handle_irq,IRQF_TRIGGER_FALLING , id->name, indio_dev);if (ret <0 ) {
Re: [PATCH v5 1/8] drivers: fwnode: fix fwnode_irq_get[_byname]()
In reply to Matti VaittinenFri, May 19, 2023 at 02:00:54PM +0300, Matti Vaittinen kirjoitti:
Quoted 15 lines
The
fwnode_irq_get()and thefwnode_irq_get_byname()return 0 upon device-tree IRQ mapping failure. This is contradicting thefwnode_irq_get_byname()function documentation and can potentially be a source of errors like:int probe(...) { ... irq = fwnode_irq_get_byname(); if (irq <= 0) return irq; ... }
Quoted 7 lines
Here we do correctly check the return value from
fwnode_irq_get_byname()but the driver probe will now return success. (There was already one such user in-tree).Change the
fwnode_irq_get_byname()to work as documented and make also thefwnode_irq_get()follow same common convention returning a negative errno upon failure.
Quoted 27 lines
Fixes ca0acb511c21 ("device property: Add fwnode_irq_get_byname")Suggested-by Sakari Ailus <[email protected]>Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Matti Vaittinen <[email protected]>---
I dropped the existing reviewed-by tags because change tofwnode_irq_get()was added.Revision history:
v3 => v4:
- Change also thefwnode_irq_get()--- drivers/base/property.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/base/property.c +1
-2@@ -987,12 +987,18 @@ EXPORT_SYMBOL(fwnode_iomap);* @fwnode: Pointer to the firmware node * @index: Zero-based index of the IRQ * -* Return: Linux IRQ number on success. Other values are determined -* according to acpi_irq_get() or of_irq_get() operation. +* Return: Linux IRQ number on success. Negative errno on failure.
drivers/base/property.c EXPORT_SYMBOL(fwnode_iomap); · line 999
Quoted 10 lines
drivers/base/property.c +6
-1*/ int fwnode_irq_get (const struct fwnode_handle *fwnode,unsigned int index) { -return fwnode_call_int_op (fwnode, irq_get, index); +int ret; + + ret =fwnode_call_int_op (fwnode, irq_get, index); +/* We treat mapping errors as invalid case */ +if (ret ==0 ) +return -EINVAL ;
Not sure if this is the best choice, perhaps -EEXIST or -ENOENT might be better, but it's just a spoken up thought.
Quoted 3 lines
drivers/base/property.c +1
-0+return ret; }EXPORT_SYMBOL (fwnode_irq_get);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 2/8] iio: mb1232: relax return value check for IRQ get
In reply to Matti VaittinenFri, May 19, 2023 at 02:01:23PM +0300, Matti Vaittinen kirjoitti:
Quoted 5 lines
fwnode_irq_get()was changed to not return 0 anymore.Drop check for return value 0.
Signed-off-by Matti Vaittinen <[email protected]>
With or without below being addressed,
Quoted 25 lines
---
Revsion history:
v4 => v5:
- drop unnecessarydata->irqnr= -1 assignmentThe 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/iio/proximity/mb1232.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/iio/proximity/mb1232.c +1
-1@@ -76,7 +76,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data) goto error_unlock; } -if (data->irqnr >=0 ) { +if (data->irqnr >0 ) {/* it cannot take more than 100 ms */ ret =wait_for_completion_killable_timeout (&data->ranging,HZ /10 );
drivers/iio/proximity/mb1232.c static int mb1232_probe(struct i2c_client *client) · line 216
Quoted 5 lines
drivers/iio/proximity/mb1232.c +0
-2@@ -212,10 +212,7 @@ static int mb1232_probe(struct i2c_client *client)init_completion (&data->ranging); data->irqnr =fwnode_irq_get (dev_fwnode (&client->dev),0 ); -if (data->irqnr <=0 ) { -/* usage of interrupt is optional */
Maybe this comment can be kept.
Quoted 6 lines
drivers/iio/proximity/mb1232.c +1
-2- data->irqnr =-1 ; - }else { +if (data->irqnr >0 ) { ret =devm_request_irq (dev, data->irqnr, mb1232_handle_irq,IRQF_TRIGGER_FALLING , id->name, indio_dev);if (ret <0 ) {
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 3/8] net-next: mvpp2: relax return value check for IRQ get
In reply to Matti VaittinenFri, May 19, 2023 at 02:01:47PM +0300, Matti Vaittinen kirjoitti:
Quoted 3 lines
fwnode_irq_get[_byname]() were changed to not return 0 anymore.
Drop check for return value 0.
...
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, · line 5837
Quoted 3 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +1
-1-if (v->irq <=0 ) { +if (v->irq <0 ) { ret = -EINVAL ;
ret = v->irq;
?
Quoted 2 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +0
-0goto err; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 4/8] pinctrl: wpcm450: relax return value check for IRQ get
In reply to Matti VaittinenFri, May 19, 2023 at 02:02:16PM +0300, Matti Vaittinen kirjoitti:
Quoted 18 lines
fwnode_irq_get[_byname]() were changed to not return 0 anymore. The special error case where device-tree based IRQ mapping fails can't no longer be reliably detected from this return value. This yields a functional change in the driver where the mapping failure is treated as an error.
The mapping failure can occur for example when the device-tree IRQ information translation call-back(s) (xlate) fail, IRQ domain is not found, IRQ type conflicts, etc. In most cases this indicates an error in the device-tree and special handling is not really required.
One more thing to note is that ACPI APIs do not return zero for any failures so this special handling did only apply on device-tree based systems.
Drop the special (no error, just skip the IRQ) handling for DT mapping failures as these can no longer be separated from other errors at driver side.
...
Quoted 11 lines
The commit message does not mention if choosing not to abort the probe on device-tree mapping failure (as is done on other errors) was chosen
because: a) Abort would have broken some existing setup. b) Because skipping an IRQ on failure is "the right thing to do", or c) because it sounded like a way to minimize risk of breaking something.If the reason is a) - then I'd appreciate receiving some more information and a suggestion how to proceed (if possible). If the reason is b), then it might be best to just skip the IRQ instead of aborting the probe for all errors on IRQ getting. Finally, in case of c), well, by acking this change you will now accept the risk :)
No need to repeat this. As I answered the case c) was in my mind when I made that change.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 3/8] net-next: mvpp2: relax return value check for IRQ get
In reply to [email protected]Hi Andy,
Quoted 7 lines · On 5/21/23 20:19, [email protected] wrote:
Fri, May 19, 2023 at 02:01:47PM +0300, Matti Vaittinen kirjoitti:
Quoted 3 lines
fwnode_irq_get[_byname]() were changed to not return 0 anymore.
Drop check for return value 0.
...
Quoted 7 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, · line 5837
Quoted 3 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +1
-1-if (v->irq <=0 ) { +if (v->irq <0 ) { ret = -EINVAL ;ret = v->irq;?
For me that seems to be correct, yes. This, however, would be a functional change and in my opinion it should be done separately from this API change.
Quoted 4 lines
Quoted 3 lines
goto err; }
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Re: [PATCH v5 4/8] pinctrl: wpcm450: relax return value check for IRQ get
In reply to [email protected]Quoted 28 lines · On 5/21/23 20:20, [email protected] wrote:
Fri, May 19, 2023 at 02:02:16PM +0300, Matti Vaittinen kirjoitti:
Quoted 18 lines
fwnode_irq_get[_byname]() were changed to not return 0 anymore. The special error case where device-tree based IRQ mapping fails can't no longer be reliably detected from this return value. This yields a functional change in the driver where the mapping failure is treated as an error.
The mapping failure can occur for example when the device-tree IRQ information translation call-back(s) (xlate) fail, IRQ domain is not found, IRQ type conflicts, etc. In most cases this indicates an error in the device-tree and special handling is not really required.
One more thing to note is that ACPI APIs do not return zero for any failures so this special handling did only apply on device-tree based systems.
Drop the special (no error, just skip the IRQ) handling for DT mapping failures as these can no longer be separated from other errors at driver side.
...
Quoted 6 lines
The commit message does not mention if choosing not to abort the probe on device-tree mapping failure (as is done on other errors) was chosen
because: a) Abort would have broken some existing setup. b) Because skipping an IRQ on failure is "the right thing to do", or c) because it sounded like a way to minimize risk of breaking something.
Quoted 8 lines
Quoted 5 lines
If the reason is a) - then I'd appreciate receiving some more information and a suggestion how to proceed (if possible). If the reason is b), then it might be best to just skip the IRQ instead of aborting the probe for all errors on IRQ getting. Finally, in case of c), well, by acking this change you will now accept the risk :)
No need to repeat this. As I answered the case c) was in my mind when I made that change.
True. I'll drop that if I re-spin. Thanks for pointing it out.
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Jonathan Cameron
maintainerRe: [PATCH v5 3/8] net-next: mvpp2: relax return value check for IRQ get
In reply to Matti VaittinenQuoted 16 lines · On Mon, 22 May 2023 08:15:01 +0300 Matti Vaittinen <[email protected]>…
Hi Andy,
Quoted 13 lines · On 5/21/23 20:19, [email protected] wrote:
Fri, May 19, 2023 at 02:01:47PM +0300, Matti Vaittinen kirjoitti:
Quoted 3 lines
fwnode_irq_get[_byname]() were changed to not return 0 anymore.
Drop check for return value 0.
...
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static int mvpp2_multi_queue_vectors_init(struct mvpp2_port *port, · line 5837
Quoted 3 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +1
-1-if (v->irq <=0 ) { +if (v->irq <0 ) { ret = -EINVAL ;ret = v->irq;
Quoted 5 lines
Quoted 1 line
?
For me that seems to be correct, yes. This, however, would be a functional change and in my opinion it should be done separately from this API change.
Ah. I commented on this as well in v6. Roll us that separate patch and I expect we'll both be happy ;)
Jonathan
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
goto err; }