From: Rosen Penev <rosenp@gmail.com>
To: netdev@vger.kernel.org
Cc: Joyce Ooi <joyce.ooi@intel.com>,
linux@armlinux.org.uk, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net-next 1/2] net: altera: use devm for alloc_etherdev
Date: Tue, 3 Dec 2024 15:31:49 -0800 [thread overview]
Message-ID: <20241203233150.184194-2-rosenp@gmail.com> (raw)
In-Reply-To: <20241203233150.184194-1-rosenp@gmail.com>
Remove a bunch of gotos as a result.
As this driver already uses devm, it makes sense to register
alloc_etherdev with devm before anything else.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/altera/altera_tse_main.c | 61 ++++++++-----------
1 file changed, 24 insertions(+), 37 deletions(-)
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 3f6204de9e6b..52d4cafec683 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1141,9 +1141,11 @@ static int altera_tse_probe(struct platform_device *pdev)
struct mii_bus *pcs_bus;
struct net_device *ndev;
void __iomem *descmap;
+ struct device *dev;
int ret = -ENODEV;
- ndev = alloc_etherdev(sizeof(struct altera_tse_private));
+ dev = &pdev->dev;
+ ndev = devm_alloc_etherdev(dev, sizeof(struct altera_tse_private));
if (!ndev) {
dev_err(&pdev->dev, "Could not allocate network device\n");
return -ENODEV;
@@ -1163,7 +1165,7 @@ static int altera_tse_probe(struct platform_device *pdev)
/* Get the mapped address to the SGDMA descriptor memory */
ret = request_and_map(pdev, "s1", &dma_res, &descmap);
if (ret)
- goto err_free_netdev;
+ return ret;
/* Start of that memory is for transmit descriptors */
priv->tx_dma_desc = descmap;
@@ -1182,26 +1184,24 @@ static int altera_tse_probe(struct platform_device *pdev)
if (upper_32_bits(priv->rxdescmem_busaddr)) {
dev_dbg(priv->device,
"SGDMA bus addresses greater than 32-bits\n");
- ret = -EINVAL;
- goto err_free_netdev;
+ return -EINVAL;
}
if (upper_32_bits(priv->txdescmem_busaddr)) {
dev_dbg(priv->device,
"SGDMA bus addresses greater than 32-bits\n");
- ret = -EINVAL;
- goto err_free_netdev;
+ return -EINVAL;
}
} else if (priv->dmaops &&
priv->dmaops->altera_dtype == ALTERA_DTYPE_MSGDMA) {
ret = request_and_map(pdev, "rx_resp", &dma_res,
&priv->rx_dma_resp);
if (ret)
- goto err_free_netdev;
+ return ret;
ret = request_and_map(pdev, "tx_desc", &dma_res,
&priv->tx_dma_desc);
if (ret)
- goto err_free_netdev;
+ return ret;
priv->txdescmem = resource_size(dma_res);
priv->txdescmem_busaddr = dma_res->start;
@@ -1209,44 +1209,40 @@ static int altera_tse_probe(struct platform_device *pdev)
ret = request_and_map(pdev, "rx_desc", &dma_res,
&priv->rx_dma_desc);
if (ret)
- goto err_free_netdev;
+ return ret;
priv->rxdescmem = resource_size(dma_res);
priv->rxdescmem_busaddr = dma_res->start;
- } else {
- ret = -ENODEV;
- goto err_free_netdev;
- }
+ } else
+ return -ENODEV;
if (!dma_set_mask(priv->device, DMA_BIT_MASK(priv->dmaops->dmamask))) {
dma_set_coherent_mask(priv->device,
DMA_BIT_MASK(priv->dmaops->dmamask));
} else if (!dma_set_mask(priv->device, DMA_BIT_MASK(32))) {
dma_set_coherent_mask(priv->device, DMA_BIT_MASK(32));
- } else {
- ret = -EIO;
- goto err_free_netdev;
- }
+ } else
+ return -EIO;
/* MAC address space */
ret = request_and_map(pdev, "control_port", &control_port,
(void __iomem **)&priv->mac_dev);
if (ret)
- goto err_free_netdev;
+ return ret;
/* xSGDMA Rx Dispatcher address space */
ret = request_and_map(pdev, "rx_csr", &dma_res,
&priv->rx_dma_csr);
if (ret)
- goto err_free_netdev;
+ return ret;
/* xSGDMA Tx Dispatcher address space */
ret = request_and_map(pdev, "tx_csr", &dma_res,
&priv->tx_dma_csr);
if (ret)
- goto err_free_netdev;
+ return ret;
memset(&pcs_regmap_cfg, 0, sizeof(pcs_regmap_cfg));
memset(&mrc, 0, sizeof(mrc));
@@ -1274,10 +1270,9 @@ static int altera_tse_probe(struct platform_device *pdev)
/* Create a regmap for the PCS so that it can be used by the PCS driver */
pcs_regmap = devm_regmap_init_mmio(&pdev->dev, priv->pcs_base,
&pcs_regmap_cfg);
- if (IS_ERR(pcs_regmap)) {
- ret = PTR_ERR(pcs_regmap);
- goto err_free_netdev;
- }
+ if (IS_ERR(pcs_regmap))
+ return PTR_ERR(pcs_regmap);
+
mrc.regmap = pcs_regmap;
mrc.parent = &pdev->dev;
mrc.valid_addr = 0x0;
@@ -1287,31 +1282,27 @@ static int altera_tse_probe(struct platform_device *pdev)
priv->rx_irq = platform_get_irq_byname(pdev, "rx_irq");
if (priv->rx_irq == -ENXIO) {
dev_err(&pdev->dev, "cannot obtain Rx IRQ\n");
- ret = -ENXIO;
- goto err_free_netdev;
+ return -ENXIO;
}
/* Tx IRQ */
priv->tx_irq = platform_get_irq_byname(pdev, "tx_irq");
if (priv->tx_irq == -ENXIO) {
dev_err(&pdev->dev, "cannot obtain Tx IRQ\n");
- ret = -ENXIO;
- goto err_free_netdev;
+ return -ENXIO;
}
/* get FIFO depths from device tree */
if (of_property_read_u32(pdev->dev.of_node, "rx-fifo-depth",
&priv->rx_fifo_depth)) {
dev_err(&pdev->dev, "cannot obtain rx-fifo-depth\n");
- ret = -ENXIO;
- goto err_free_netdev;
+ return -ENXIO;
}
if (of_property_read_u32(pdev->dev.of_node, "tx-fifo-depth",
&priv->tx_fifo_depth)) {
dev_err(&pdev->dev, "cannot obtain tx-fifo-depth\n");
- ret = -ENXIO;
- goto err_free_netdev;
+ return -ENXIO;
}
/* get hash filter settings for this instance */
@@ -1354,7 +1345,7 @@ static int altera_tse_probe(struct platform_device *pdev)
ret = altera_tse_phy_get_addr_mdio_create(ndev);
if (ret)
- goto err_free_netdev;
+ return ret;
/* initialize netdev */
ndev->mem_start = control_port->start;
@@ -1450,8 +1441,6 @@ static int altera_tse_probe(struct platform_device *pdev)
err_register_netdev:
netif_napi_del(&priv->napi);
altera_tse_mdio_destroy(ndev);
-err_free_netdev:
- free_netdev(ndev);
return ret;
}
@@ -1467,8 +1456,6 @@ static void altera_tse_remove(struct platform_device *pdev)
unregister_netdev(ndev);
phylink_destroy(priv->phylink);
lynx_pcs_destroy(priv->pcs);
-
- free_netdev(ndev);
}
static const struct altera_dmaops altera_dtype_sgdma = {
--
2.47.0
next prev parent reply other threads:[~2024-12-03 23:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 23:31 [PATCH net-next 0/2] altera: simplify probe Rosen Penev
2024-12-03 23:31 ` Rosen Penev [this message]
2024-12-03 23:31 ` [PATCH net-next 2/2] net: altera: simplify request_and_map Rosen Penev
2024-12-05 3:27 ` [PATCH net-next 0/2] altera: simplify probe 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=20241203233150.184194-2-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=joyce.ooi@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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).