net: ethernet: sun4i-emac: Fix IRQ error handling
Subsystems (3)
PATCH 1/1 net: ethernet: sun4i-emac: Fix IRQ error handling
From: bui duc phuc <[email protected]>
irq_of_parse_and_map() returns 0 when parsing or mapping an IRQ fails. The current code checks for -ENXIO and therefore does not detect the failure.
Check for a zero return value and convert it to -ENXIO.
--- drivers/net/ethernet/allwinner/sun4i-emac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/allwinner/sun4i-emac.c +2 -2
@@ -996,9 +996,9 @@ static int emac_probe(struct platform_device *pdev)/* fill in parameters for net-dev structure */ ndev->base_addr = (unsigned long )db->membase; ndev->irq =irq_of_parse_and_map (np,0 ); -if (ndev->irq == -ENXIO ) { +if (!ndev->irq) {netdev_err (ndev,"No irq resource\n" ); - ret = ndev->irq; + ret = -ENXIO ; goto out_iounmap; }
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Unconditional call to dma_release_channel(db->rx_chan) in the emac_probe() error path can cause a kernel panic if DMA configuration fails.
- [High] The driver unconditionally enables MAC interrupts during system resume, even if the network interface was logically down, which can permanently break the interface. --
--- Patch [1]: [PATCH net] net: ethernet: sun4i-emac: Fix IRQ error handling --- commit aeff88d2fcbccbc3cb84803b3c45048b12777cd3
Author: bui duc phuc <[email protected]>
net: ethernet: sun4i-emac: Fix IRQ error handling
irq_of_parse_and_map() returns 0 when parsing or mapping an IRQ fails. The current code checks for -ENXIO and therefore does not detect the failure.
Check for a zero return value and convert it to -ENXIO.
Quoted 6 lines
drivers/net/ethernet/allwinner/sun4i-emac.c +0
-0@@ -996,9 +996,9 @@ static int emac_probe(struct platform_device *pdev)/* fill in parameters for net-dev structure */
drivers/net/ethernet/allwinner/sun4i-emac.c static int emac_probe(struct platform_device *pdev) · line 1004
Quoted 10 lines
drivers/net/ethernet/allwinner/sun4i-emac.c +2
-2ndev->base_addr = (unsigned long )db->membase; ndev->irq =irq_of_parse_and_map (np,0 ); -if (ndev->irq == -ENXIO ) { +if (!ndev->irq) {netdev_err (ndev,"No irq resource\n" ); - ret = ndev->irq; + ret = -ENXIO ; goto out_iounmap; }
[Severity: High]
This isn't a bug introduced by this patch, but is there a pre-existing panic risk during error handling later in emac_probe()?
If emac_configure_dma() fails, it explicitly sets db->rx_chan to NULL:
drivers/net/ethernet/allwinner/sun4i-emac.c:emac_configure_dma() {
...
db->rx_chan = NULL;
...
}If a subsequent initialization step such as devm_clk_get() fails, the probe error path unconditionally calls dma_release_channel():
drivers/net/ethernet/allwinner/sun4i-emac.c:emac_probe() {
...
out_dispose_mapping:
irq_dispose_mapping(ndev->irq);
dma_release_channel(db->rx_chan);
...
}Will dma_release_channel() dereference the null channel pointer (via chan->client_count) without checking for a null value first?
[Severity: High]
This is also a pre-existing issue, but does emac_resume() unconditionally enable mac interrupts even if the network interface is down?
If the system goes to sleep while the interface is logically down (meaning emac_open() was never called and no irq handler is registered), the resume handler still calls emac_init_device():
drivers/net/ethernet/allwinner/sun4i-emac.c:emac_resume() {
...
emac_init_device(ndev);
...
}Which in turn enables hardware interrupts:
drivers/net/ethernet/allwinner/sun4i-emac.c:emac_init_device() {
...
writel(reg_val, db->membase + EMAC_INT_CTL_REG);
...
}If the hardware subsequently asserts an interrupt (for example, from broadcast packets) but no handler is registered, will this cause an interrupt storm that forces the generic irq subsystem to permanently disable the interrupt line?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 4 lines
Pre-existing issues:
- [High] Unconditional call todma_release_channel(db->rx_chan)in theemac_probe()error path can cause a kernel panic if DMA configuration fails.
- [High] The driver unconditionally enables MAC interrupts during system resume, even if the network interface was logically down, which can permanently break the interface. --
Both issues are pre-existing and are not introduced by this patch. I will keep the scope of this patch limited to IRQ error handling and will not address these issues here.
For the first issue, the cleanup could be separated so that dma_release_channel() is only reached after successful DMA configuration:
---------------------------------------------------------
- if (emac_configure_dma(db))
+ ret = emac_configure_dma(db);
+ if (ret) {
netdev_info(ndev, "configure dma failed. disable dma.\n");
+ goto out_dispose_mapping;
+ }
...
if (IS_ERR(db->clk)) {
ret = PTR_ERR(db->clk);
- goto out_dispose_mapping;
+ goto out_release_dma;
}...
+out_release_dma:
+ dma_release_channel(db->rx_chan);
out_dispose_mapping:
irq_dispose_mapping(ndev->irq);
- dma_release_channel(db->rx_chan);
------------------------------------------------------------
I will not include this change in the current patch. These issues would be better addressed and tested by someone with access to the hardware.
Hi,
Quoted 7 lines · On 8/24/26 12:09, [email protected] wrote:
From: bui duc phuc <[email protected]>
irq_of_parse_and_map()returns 0 when parsing or mapping an IRQ fails. The current code checks for-ENXIOand therefore does not detect the failure.Check for a zero return value and convert it to
-ENXIO.
Yes, the return value is the IRQ number, or 0 in case of a missing IRQ.
Quoted 2 lines
Fixes 492205050d77 ("net: Add EMAC ethernet driver found on Allwinner A10 SoC's")Signed-off-by bui duc phuc <[email protected]>
Thanks,
Andre
Quoted 20 lines
--- drivers/net/ethernet/allwinner/sun4i-emac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/allwinner/sun4i-emac.c +2
-2@@ -996,9 +996,9 @@ static int emac_probe(struct platform_device *pdev)/* fill in parameters for net-dev structure */ ndev->base_addr = (unsigned long )db->membase; ndev->irq =irq_of_parse_and_map (np,0 ); -if (ndev->irq == -ENXIO ) { +if (!ndev->irq) {netdev_err (ndev,"No irq resource\n" ); - ret = ndev->irq; + ret = -ENXIO ; goto out_iounmap; }
Hi Andre,
Thank you for your review and the Reviewed-by tag.
Quoted 3 lines
Reviewed-by Andre Przywara <[email protected]>
Best regards,
Phuc
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Mon, 24 Aug 2026 17:09:01 +0700 you wrote:
From: bui duc phuc <[email protected]>
irq_of_parse_and_map()returns 0 when parsing or mapping an IRQ fails. The current code checks for-ENXIOand therefore does not detect the failure.Check for a zero return value and convert it to
-ENXIO.[...]
Here is the summary with links:
- [net] net: ethernet: sun4i-emac: Fix IRQ error handling
https://git.kernel.org/netdev/net/c/991c2be78257
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html