[PATCH v2] net: moxa: dispose IRQ mappings on probe failure and device removal
Diego Fernando Mancera Gomez <[email protected]>
| Newsgroups | org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
moxart_mac_probe() maps the interrupt with irq_of_parse_and_map() but
never disposes of the mapping on the error paths that follow a
successful mapping, and neither does moxart_remove(). Every failed
probe (for example EPROBE_DEFER from platform_get_ethdev_address(),
DMA allocation failures or register_netdev() failure) and every device
removal therefore leaks the interrupt mapping.
Since irq_of_parse_and_map() is not a devm API, dispose of the mapping
the traditional way: all error paths after a successful mapping fall
through init_fail to a single irq_dispose_mapping(), and the
register_netdev() failure path additionally releases the handler with
devm_free_irq() first via a dedicated label, so the devres-managed IRQ
is never released against a disposed mapping or a freed netdev.
moxart_remove() releases the handler and disposes of the mapping before
freeing the netdev.
Fixes: 6c821bd9edc9 ("net: Add MOXA ART SoCs ethernet driver")
Signed-off-by: Diego Fernando Mancera Gomez <[email protected]>
---
Changes in v2:
- Use the traditional IRQ mapping cleanup path as requested by Andrew Lunn.
drivers/net/ethernet/moxa/moxart_ether.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
index 8bd60168624a..8f79ff24aa05 100644
--- a/drivers/net/ethernet/moxa/moxart_ether.c
+++ b/drivers/net/ethernet/moxa/moxart_ether.c
@@ -543,15 +543,18 @@ static int moxart_mac_probe(struct platform_device *pdev)
ret = register_netdev(ndev);
if (ret)
- goto init_fail;
+ goto free_irq_dispose;
netdev_dbg(ndev, "%s: IRQ=%d address=%pM\n",
__func__, ndev->irq, ndev->dev_addr);
return 0;
+free_irq_dispose:
+ devm_free_irq(p_dev, irq, ndev);
init_fail:
netdev_err(ndev, "init failed\n");
+ irq_dispose_mapping(irq);
moxart_mac_free_memory(ndev);
irq_map_fail:
free_netdev(ndev);
@@ -564,6 +567,7 @@ static void moxart_remove(struct platform_device *pdev)
unregister_netdev(ndev);
devm_free_irq(&pdev->dev, ndev->irq, ndev);
+ irq_dispose_mapping(ndev->irq);
moxart_mac_free_memory(ndev);
free_netdev(ndev);
}
--
2.54.0.windows.1