From: Diego Fernando Mancera Gomez <diegomancera.dev@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jonas.jensen@gmail.com
Subject: [PATCH] net: moxa: dispose IRQ mappings on probe failure and device removal
Date: Fri, 14 Aug 2026 11:54:03 -0600 [thread overview]
Message-ID: <20260814175404.1616-1-diegomancera.dev@gmail.com> (raw)
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
next reply other threads:[~2026-08-14 17:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 17:54 Diego Fernando Mancera Gomez [this message]
2026-08-14 18:14 ` [PATCH] net: moxa: dispose IRQ mappings on probe failure and device removal Andrew Lunn
2026-08-14 18:42 ` [PATCH v2] " Diego Fernando Mancera Gomez
2026-08-14 18:50 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260814175404.1616-1-diegomancera.dev@gmail.com \
--to=diegomancera.dev@gmail.com \
--cc=davem@davemloft.net \
--cc=jonas.jensen@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox