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 2/2] net: altera: simplify request_and_map
Date: Tue, 3 Dec 2024 15:31:50 -0800 [thread overview]
Message-ID: <20241203233150.184194-3-rosenp@gmail.com> (raw)
In-Reply-To: <20241203233150.184194-1-rosenp@gmail.com>
This function is effectively devm_platform_ioremap_resource_byname with
an additional parameter returning the resource. Might as well use modern
helpers.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/altera/altera_tse_main.c | 81 ++++++-------------
1 file changed, 26 insertions(+), 55 deletions(-)
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 52d4cafec683..66add91e64e0 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1098,33 +1098,11 @@ static const struct phylink_mac_ops alt_tse_phylink_ops = {
.mac_select_pcs = alt_tse_select_pcs,
};
-static int request_and_map(struct platform_device *pdev, const char *name,
- struct resource **res, void __iomem **ptr)
+static void __iomem *request_and_map(struct platform_device *pdev,
+ const char *name, struct resource **res)
{
- struct device *device = &pdev->dev;
- struct resource *region;
-
*res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
- if (*res == NULL) {
- dev_err(device, "resource %s not defined\n", name);
- return -ENODEV;
- }
-
- region = devm_request_mem_region(device, (*res)->start,
- resource_size(*res), dev_name(device));
- if (region == NULL) {
- dev_err(device, "unable to request %s\n", name);
- return -EBUSY;
- }
-
- *ptr = devm_ioremap(device, region->start,
- resource_size(region));
- if (*ptr == NULL) {
- dev_err(device, "ioremap of %s failed!", name);
- return -ENOMEM;
- }
-
- return 0;
+ return devm_ioremap_resource(&pdev->dev, *res);
}
/* Probe Altera TSE MAC device
@@ -1163,9 +1141,9 @@ static int altera_tse_probe(struct platform_device *pdev)
if (priv->dmaops &&
priv->dmaops->altera_dtype == ALTERA_DTYPE_SGDMA) {
/* Get the mapped address to the SGDMA descriptor memory */
- ret = request_and_map(pdev, "s1", &dma_res, &descmap);
- if (ret)
- return ret;
+ descmap = request_and_map(pdev, "s1", &dma_res);
+ if (IS_ERR(descmap))
+ return PTR_ERR(descmap);
/* Start of that memory is for transmit descriptors */
priv->tx_dma_desc = descmap;
@@ -1193,23 +1171,20 @@ static int altera_tse_probe(struct platform_device *pdev)
}
} 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)
- return ret;
+ priv->rx_dma_resp = request_and_map(pdev, "rx_resp", &dma_res);
+ if (IS_ERR(priv->rx_dma_resp))
+ return PTR_ERR(priv->rx_dma_resp);
- ret = request_and_map(pdev, "tx_desc", &dma_res,
- &priv->tx_dma_desc);
- if (ret)
- return ret;
+ priv->tx_dma_desc = request_and_map(pdev, "tx_desc", &dma_res);
+ if (IS_ERR(priv->tx_dma_desc))
+ return PTR_ERR(priv->tx_dma_desc);
priv->txdescmem = resource_size(dma_res);
priv->txdescmem_busaddr = dma_res->start;
- ret = request_and_map(pdev, "rx_desc", &dma_res,
- &priv->rx_dma_desc);
- if (ret)
- return ret;
+ priv->rx_dma_desc = request_and_map(pdev, "rx_desc", &dma_res);
+ if (IS_ERR(priv->rx_dma_desc))
+ return PTR_ERR(priv->rx_dma_desc);
priv->rxdescmem = resource_size(dma_res);
priv->rxdescmem_busaddr = dma_res->start;
@@ -1226,23 +1201,19 @@ static int altera_tse_probe(struct platform_device *pdev)
return -EIO;
/* MAC address space */
- ret = request_and_map(pdev, "control_port", &control_port,
- (void __iomem **)&priv->mac_dev);
- if (ret)
- return ret;
+ priv->mac_dev = request_and_map(pdev, "control_port", &control_port);
+ if (IS_ERR(priv->mac_dev))
+ return PTR_ERR(priv->mac_dev);
/* xSGDMA Rx Dispatcher address space */
- ret = request_and_map(pdev, "rx_csr", &dma_res,
- &priv->rx_dma_csr);
- if (ret)
- return ret;
-
+ priv->rx_dma_csr = request_and_map(pdev, "rx_csr", &dma_res);
+ if (IS_ERR(priv->rx_dma_csr))
+ return PTR_ERR(priv->rx_dma_csr);
/* xSGDMA Tx Dispatcher address space */
- ret = request_and_map(pdev, "tx_csr", &dma_res,
- &priv->tx_dma_csr);
- if (ret)
- return ret;
+ priv->tx_dma_csr = request_and_map(pdev, "tx_csr", &dma_res);
+ if (IS_ERR(priv->tx_dma_csr))
+ return PTR_ERR(priv->tx_dma_csr);
memset(&pcs_regmap_cfg, 0, sizeof(pcs_regmap_cfg));
memset(&mrc, 0, sizeof(mrc));
@@ -1251,8 +1222,8 @@ static int altera_tse_probe(struct platform_device *pdev)
* address space, but if it's not the case, we fallback to the mdiophy0
* from the MAC's address space
*/
- ret = request_and_map(pdev, "pcs", &pcs_res, &priv->pcs_base);
- if (ret) {
+ priv->pcs_base = request_and_map(pdev, "pcs", &pcs_res);
+ if (IS_ERR(priv->pcs_base)) {
/* If we can't find a dedicated resource for the PCS, fallback
* to the internal PCS, that has a different address stride
*/
--
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 ` [PATCH net-next 1/2] net: altera: use devm for alloc_etherdev Rosen Penev
2024-12-03 23:31 ` Rosen Penev [this message]
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-3-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