* [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
2026-08-14 18:42 ` [PATCH v2] " Diego Fernando Mancera Gomez
0 siblings, 2 replies; 4+ 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] 4+ 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
2026-08-14 18:42 ` [PATCH v2] " Diego Fernando Mancera Gomez
1 sibling, 0 replies; 4+ 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] 4+ messages in thread
* [PATCH v2] 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
@ 2026-08-14 18:42 ` Diego Fernando Mancera Gomez
2026-08-14 18:50 ` Andrew Lunn
1 sibling, 1 reply; 4+ messages in thread
From: Diego Fernando Mancera Gomez @ 2026-08-14 18:42 UTC (permalink / raw)
To: netdev; +Cc: andrew, 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.
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 <diegomancera.dev@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] net: moxa: dispose IRQ mappings on probe failure and device removal
2026-08-14 18:42 ` [PATCH v2] " Diego Fernando Mancera Gomez
@ 2026-08-14 18:50 ` Andrew Lunn
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2026-08-14 18:50 UTC (permalink / raw)
To: Diego Fernando Mancera Gomez; +Cc: netdev, davem, jonas.jensen
> --- 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);
Calling devm_free_FOO() suggests there are other problems, likely a
bad conversion to devm_FOO().
Please take a look at the whole of probe() and fix all its problems.
Also, please read:
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-14 18:50 UTC | newest]
Thread overview: 4+ 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
2026-08-14 18:42 ` [PATCH v2] " Diego Fernando Mancera Gomez
2026-08-14 18:50 ` Andrew Lunn
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.