netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: netdev@vger.kernel.org
Cc: u.kleine-koenig@pengutronix.de, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next] net: moxart_ether: use devm in probe
Date: Wed,  7 Aug 2024 21:03:54 -0700	[thread overview]
Message-ID: <20240808040425.5833-1-rosenp@gmail.com> (raw)

alloc_etherdev and kmalloc_array are called first and destroyed last.
Safe to use devm to remove frees.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
index 96dc69e7141f..06c632c90494 100644
--- a/drivers/net/ethernet/moxa/moxart_ether.c
+++ b/drivers/net/ethernet/moxa/moxart_ether.c
@@ -81,9 +81,6 @@ static void moxart_mac_free_memory(struct net_device *ndev)
 		dma_free_coherent(&priv->pdev->dev,
 				  RX_REG_DESC_SIZE * RX_DESC_NUM,
 				  priv->rx_desc_base, priv->rx_base);
-
-	kfree(priv->tx_buf_base);
-	kfree(priv->rx_buf_base);
 }
 
 static void moxart_mac_reset(struct net_device *ndev)
@@ -461,15 +458,14 @@ static int moxart_mac_probe(struct platform_device *pdev)
 	unsigned int irq;
 	int ret;
 
-	ndev = alloc_etherdev(sizeof(struct moxart_mac_priv_t));
+	ndev = devm_alloc_etherdev(p_dev, sizeof(struct moxart_mac_priv_t));
 	if (!ndev)
 		return -ENOMEM;
 
 	irq = irq_of_parse_and_map(node, 0);
 	if (irq <= 0) {
 		netdev_err(ndev, "irq_of_parse_and_map failed\n");
-		ret = -EINVAL;
-		goto irq_map_fail;
+		return -EINVAL;
 	}
 
 	priv = netdev_priv(ndev);
@@ -511,15 +507,15 @@ static int moxart_mac_probe(struct platform_device *pdev)
 		goto init_fail;
 	}
 
-	priv->tx_buf_base = kmalloc_array(priv->tx_buf_size, TX_DESC_NUM,
-					  GFP_KERNEL);
+	priv->tx_buf_base = devm_kmalloc_array(p_dev, priv->tx_buf_size,
+					       TX_DESC_NUM, GFP_KERNEL);
 	if (!priv->tx_buf_base) {
 		ret = -ENOMEM;
 		goto init_fail;
 	}
 
-	priv->rx_buf_base = kmalloc_array(priv->rx_buf_size, RX_DESC_NUM,
-					  GFP_KERNEL);
+	priv->rx_buf_base = devm_kmalloc_array(p_dev, priv->rx_buf_size,
+					       RX_DESC_NUM, GFP_KERNEL);
 	if (!priv->rx_buf_base) {
 		ret = -ENOMEM;
 		goto init_fail;
@@ -553,8 +549,6 @@ static int moxart_mac_probe(struct platform_device *pdev)
 init_fail:
 	netdev_err(ndev, "init failed\n");
 	moxart_mac_free_memory(ndev);
-irq_map_fail:
-	free_netdev(ndev);
 	return ret;
 }
 
@@ -565,7 +559,6 @@ static void moxart_remove(struct platform_device *pdev)
 	unregister_netdev(ndev);
 	devm_free_irq(&pdev->dev, ndev->irq, ndev);
 	moxart_mac_free_memory(ndev);
-	free_netdev(ndev);
 }
 
 static const struct of_device_id moxart_mac_match[] = {
-- 
2.45.2


             reply	other threads:[~2024-08-08  4:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08  4:03 Rosen Penev [this message]
2024-08-08  8:18 ` [PATCH net-next] net: moxart_ether: use devm in probe Christophe JAILLET
2024-08-08 20:21   ` Rosen Penev
2024-08-08 14:58 ` Jakub Kicinski

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=20240808040425.5833-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).