* [PATCH] net: moxa: dispose IRQ mappings on probe failure and device removal
@ 2026-08-14 17:54 Diego Fernando Mancera Gomez
2026-08-14 18:14 ` Andrew Lunn
0 siblings, 1 reply; 2+ messages in thread
From: Diego Fernando Mancera Gomez @ 2026-08-14 17:54 UTC (permalink / raw)
To: netdev; +Cc: davem, jonas.jensen
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.
Register the disposal as a devres action with devm_add_action_or_reset()
immediately after irq_of_parse_and_map() and before devm_request_irq(),
so on unwind devres disposes of the mapping only after the handler has
been released, and devm_add_action_or_reset() disposes of the mapping
itself if the action cannot be registered. Since devres_release_all()
runs only after the probe error path frees the netdev, release the
handler with devm_free_irq() before free_netdev() on the error paths
that follow a successful devm_request_irq(), and likewise in
moxart_remove().
Fixes: 6c821bd9edc9 ("net: Add MOXA ART SoCs ethernet driver")
Signed-off-by: Diego Fernando Mancera Gomez <diegomancera.dev@gmail.com>
---
drivers/net/ethernet/moxa/moxart_ether.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
index 8bd60168624a..7b5720f993ae 100644
--- a/drivers/net/ethernet/moxa/moxart_ether.c
+++ b/drivers/net/ethernet/moxa/moxart_ether.c
@@ -451,6 +451,13 @@ static const struct net_device_ops moxart_netdev_ops = {
.ndo_validate_addr = eth_validate_addr,
};
+static void moxart_irq_dispose_mapping(void *data)
+{
+ unsigned int irq = (unsigned int)(uintptr_t)data;
+
+ irq_dispose_mapping(irq);
+}
+
static int moxart_mac_probe(struct platform_device *pdev)
{
struct device *p_dev = &pdev->dev;
@@ -459,6 +466,7 @@ static int moxart_mac_probe(struct platform_device *pdev)
struct moxart_mac_priv_t *priv;
struct resource *res;
unsigned int irq;
+ bool irq_requested = false;
int ret;
ndev = alloc_etherdev(sizeof(struct moxart_mac_priv_t));
@@ -472,6 +480,16 @@ static int moxart_mac_probe(struct platform_device *pdev)
goto irq_map_fail;
}
+ /* Dispose of the IRQ mapping after the devres-managed handler has
+ * been released: devres runs actions in reverse registration order,
+ * so registering this before devm_request_irq() guarantees the
+ * correct order on probe unwind and device removal.
+ */
+ ret = devm_add_action_or_reset(p_dev, moxart_irq_dispose_mapping,
+ (void *)(uintptr_t)irq);
+ if (ret)
+ goto irq_map_fail;
+
priv = netdev_priv(ndev);
priv->ndev = ndev;
priv->pdev = pdev;
@@ -533,6 +551,7 @@ static int moxart_mac_probe(struct platform_device *pdev)
netdev_err(ndev, "devm_request_irq failed\n");
goto init_fail;
}
+ irq_requested = true;
ndev->netdev_ops = &moxart_netdev_ops;
netif_napi_add_weight(ndev, &priv->napi, moxart_rx_poll, RX_DESC_NUM);
@@ -552,6 +571,8 @@ static int moxart_mac_probe(struct platform_device *pdev)
init_fail:
netdev_err(ndev, "init failed\n");
+ if (irq_requested)
+ devm_free_irq(p_dev, irq, ndev);
moxart_mac_free_memory(ndev);
irq_map_fail:
free_netdev(ndev);
--
2.54.0.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: moxa: dispose IRQ mappings on probe failure and device removal
2026-08-14 17:54 [PATCH] net: moxa: dispose IRQ mappings on probe failure and device removal Diego Fernando Mancera Gomez
@ 2026-08-14 18:14 ` Andrew Lunn
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2026-08-14 18:14 UTC (permalink / raw)
To: Diego Fernando Mancera Gomez; +Cc: netdev, davem, jonas.jensen
On Fri, Aug 14, 2026 at 11:54:03AM -0600, Diego Fernando Mancera Gomez wrote:
> moxart_mac_probe() maps the interrupt with irq_of_parse_and_map()
Since this is not a devm_ API call, please do the cleanup the old
way.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-14 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 17:54 [PATCH] net: moxa: dispose IRQ mappings on probe failure and device removal Diego Fernando Mancera Gomez
2026-08-14 18:14 ` Andrew Lunn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox