Skip to contentSkip to conversation

net: ibm: emac: fix unchecked platform_get_irq return value

PATCH Applied Rosen Penev 3 participants 3 messages Jun 1 – Jun 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ibm: emac: fix unchecked platform_get_irq return value

platform_get_irq() returns a negative errno on failure. Commit a598f66d9169 replaced irq_of_parse_and_map() (which returns 0 on failure) with platform_get_irq() but dropped the error check. Without it, a negative IRQ number is passed to devm_request_irq(), which fails with -EINVAL instead of propagating the real error from platform_get_irq().

Add the missing error check and goto err_gone.

Fixes a598f66d9169 ("net: ibm: emac: use platform_get_irq")
Assisted-by Opencode:Big-Pickle
---
 drivers/net/ethernet/ibm/emac/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/ibm/emac/core.c +5 -0
index e597e2ad434c..d2194b406c9e 100644
@@ -3035,6 +3035,11 @@ static int emac_probe(struct platform_device *ofdev)
 
 	/* Setup error IRQ handler */
 	dev->emac_irq = platform_get_irq(ofdev, 0);
+	if (dev->emac_irq < 0) {
+		err = dev->emac_irq;
+		goto err_gone;
+	}
+
 	err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC",
 			       dev);
 	if (err) {
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Rosen Penev

platform_get_irq() returns a negative errno on failure. Commit a598f66d9169 replaced irq_of_parse_and_map() (which returns 0 on failure) with platform_get_irq() but dropped the error check. Without it, a negative IRQ number is passed to devm_request_irq(), which fails with -EINVAL instead of propagating the real error from platform_get_irq().

Yep, looking through devm_request_irq, it seems most likely to fail on irq_to_desc().

Definitely more explicit to correctly check the return value, though it seems like a relatively minor cleanup since we do fail almost immediately.

Quoted 25 lines

Add the missing error check and goto err_gone.

Fixes a598f66d9169 ("net: ibm: emac: use platform_get_irq")
Assisted-by Opencode:Big-Pickle
---
 drivers/net/ethernet/ibm/emac/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/ibm/emac/core.c +5 -0
index e597e2ad434c..d2194b406c9e 100644
@@ -3035,6 +3035,11 @@ static int emac_probe(struct platform_device *ofdev)
 
 	/* Setup error IRQ handler */
 	dev->emac_irq = platform_get_irq(ofdev, 0);
+	if (dev->emac_irq < 0) {
+		err = dev->emac_irq;
+		goto err_gone;
+	}
+
 	err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC",
 			       dev);
 	if (err) {
#2 lore raw
In reply to Rosen Penev
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Sun, 31 May 2026 21:02:00 -0700 you wrote:

platform_get_irq() returns a negative errno on failure. Commit a598f66d9169 replaced irq_of_parse_and_map() (which returns 0 on failure) with platform_get_irq() but dropped the error check. Without it, a negative IRQ number is passed to devm_request_irq(), which fails with -EINVAL instead of propagating the real error from platform_get_irq().

[...]

Here is the summary with links:
- [net] net: ibm: emac: fix unchecked platform_get_irq return value

    https://git.kernel.org/netdev/net-next/c/1681cb1bde05

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html