net: emac: Fix NULL pointer dereference in emac_probe
Subsystems (2)
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().
---
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
@@ -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
Quoted 7 lines · Rosen Penev
Move
devm_request_irq()afterdevm_platform_ioremap_resource()so thatdev->emacpis mapped before the interrupt handler can fire. An early interrupt hittingemac_irq()would dereference the NULLdev->emacpand crash.Also remove redundant error message.
devm_platform_ioremap_resource()already returns an error message withdev_err_probe().
I still think there is a bigger problem that interrupts can fire early, but:
Andrew
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()afterdevm_platform_ioremap_resource()so thatdev->emacpis mapped before the interrupt handler can fire. An early interrupt hittingemac_irq()would dereference the NULLdev->emacpand crash.Also remove redundant error message.
devm_platform_ioremap_resource()already returns an error message withdev_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