All of lore.kernel.org
 help / color / mirror / Atom feed
From: Diego Fernando Mancera Gomez <diegomancera.dev@gmail.com>
To: netdev@vger.kernel.org
Cc: andrew@lunn.ch, davem@davemloft.net, jonas.jensen@gmail.com
Subject: [PATCH v2] net: moxa: dispose IRQ mappings on probe failure and device removal
Date: Fri, 14 Aug 2026 12:42:16 -0600	[thread overview]
Message-ID: <20260814184216.388-1-diegomancera.dev@gmail.com> (raw)
In-Reply-To: <20260814175404.1616-1-diegomancera.dev@gmail.com>

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

  parent reply	other threads:[~2026-08-14 18:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-08-14 18:50   ` [PATCH v2] " 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=20260814184216.388-1-diegomancera.dev@gmail.com \
    --to=diegomancera.dev@gmail.com \
    --cc=andrew@lunn.ch \
    --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 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.