Skip to contentSkip to conversation

net: emac: Fix NULL pointer dereference in emac_probe

PATCH Applied Rosen Penev 3 participants 3 messages Jun 18 – Jun 21

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

PATCH v2 1/1 net: emac: Fix NULL pointer dereference in emac_probe

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Also remove redundant error message. devm_platform_ioremap_resource() already returns an error message with dev_err_probe().

Fixes dcc34ef7c834 ("net: ibm: emac: manage emac_irq with devm")
Assisted-by Opencode:Big-Pickle

---
v2: remove redundant error message.

 drivers/net/ethernet/ibm/emac/core.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +6 -7
index 80f0c8985845..62ee1b70c3e7 100644
@@ -3044,6 +3044,12 @@ static int emac_probe(struct platform_device *ofdev)
 	if (err)
 		goto err_gone;
 
+	dev->emacp = devm_platform_ioremap_resource(ofdev, 0);
+	if (IS_ERR(dev->emacp)) {
+		err = PTR_ERR(dev->emacp);
+		goto err_gone;
+	}
+
 	/* Setup error IRQ handler */
 	dev->emac_irq = platform_get_irq(ofdev, 0);
 	if (dev->emac_irq < 0) {
@@ -3061,13 +3067,6 @@ static int emac_probe(struct platform_device *ofdev)
 
 	ndev->irq = dev->emac_irq;
 
-	dev->emacp = devm_platform_ioremap_resource(ofdev, 0);
-	if (IS_ERR(dev->emacp)) {
-		dev_err(&ofdev->dev, "can't map device registers");
-		err = PTR_ERR(dev->emacp);
-		goto err_gone;
-	}
-
 	/* Wait for dependent devices */
 	err = emac_wait_deps(dev);
 	if (err)

--
2.54.0

Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Rosen Penev

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Also remove redundant error message. devm_platform_ioremap_resource() already returns an error message with dev_err_probe().

I still think there is a bigger problem that interrupts can fire early, but:

Andrew

#2 lore raw
In reply to Rosen Penev
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 9 lines · On Wed, 17 Jun 2026 19:34:05 -0700 you wrote:

Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.

Also remove redundant error message. devm_platform_ioremap_resource() already returns an error message with dev_err_probe().

[...]

Here is the summary with links:
- [PATCHv2] net: emac: Fix NULL pointer dereference in emac_probe

    https://git.kernel.org/netdev/net/c/f623d38fe6c4

You are awesome, thank you!

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