diff mbox series

[net-next,v2] net: gemini: Use devm_platform_get_and_ioremap_resource()

Message ID 20210605123636.2485041-1-yangyingliang@huawei.com
State New
Headers show
Series [net-next,v2] net: gemini: Use devm_platform_get_and_ioremap_resource() | expand

Commit Message

Yang Yingliang June 5, 2021, 12:36 p.m. UTC
Use devm_platform_get_and_ioremap_resource() to simplify
code.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v2:
  Also use devm_platform_get_and_ioremap_resource() in gemini_ethernet_probe().
  Keep the error message to distinguish remap which address failed in
  gemini_ethernet_port_probe().
---
 drivers/net/ethernet/cortina/gemini.c | 28 +++++++++------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

Comments

Yang Yingliang June 7, 2021, 1:05 a.m. UTC | #1
Hi,

On 2021/6/5 23:17, Linus Walleij wrote:
> On Sat, Jun 5, 2021 at 2:32 PM Yang Yingliang <yangyingliang@huawei.com> wrote:

>

>> Use devm_platform_get_and_ioremap_resource() to simplify

>> code.

>>

>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

> (...)

>> -       dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);

>> -       gmacres = platform_get_resource(pdev, IORESOURCE_MEM, 1);

> Should you not also delete the local variables

> dmares and gmacres? I doubt they are used

> after this.

They are used to print message before returning gemini_ethernet_port_probe()
static int gemini_ethernet_port_probe(struct platform_device *pdev)
{
[...]
         netdev_info(netdev,
                     "irq %d, DMA @ 0x%pap, GMAC @ 0x%pap\n",
                     port->irq, &dmares->start,
                     &gmacres->start);
         return 0;

unprepare:
         clk_disable_unprepare(port->pclk);
         return ret;
}

Thanks,
Yang
>

> Yours,

> Linus Walleij

> .
Linus Walleij June 7, 2021, 6:49 a.m. UTC | #2
On Mon, Jun 7, 2021 at 3:05 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
> On 2021/6/5 23:17, Linus Walleij wrote:

> > On Sat, Jun 5, 2021 at 2:32 PM Yang Yingliang <yangyingliang@huawei.com> wrote:

> >

> >> Use devm_platform_get_and_ioremap_resource() to simplify

> >> code.

> >>

> >> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

> > (...)

> >> -       dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);

> >> -       gmacres = platform_get_resource(pdev, IORESOURCE_MEM, 1);

> > Should you not also delete the local variables

> > dmares and gmacres? I doubt they are used

> > after this.

>

> They are used to print message before returning gemini_ethernet_port_probe()

> static int gemini_ethernet_port_probe(struct platform_device *pdev)


Yes and after this they will print something undefined since you never
assign them anything, so the dmares and gmacres prints need to be
removed too. (Which is fine.)

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 8df6f081f244..6f7ff1f1fb2b 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2390,24 +2390,18 @@  static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	port->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
 
 	/* DMA memory */
-	dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!dmares) {
-		dev_err(dev, "no DMA resource\n");
-		return -ENODEV;
-	}
-	port->dma_base = devm_ioremap_resource(dev, dmares);
-	if (IS_ERR(port->dma_base))
+	port->dma_base = devm_platform_get_and_ioremap_resource(pdev, 0, &dmares);
+	if (IS_ERR(port->dma_base)) {
+		dev_err(dev, "get DMA address failed\n");
 		return PTR_ERR(port->dma_base);
+	}
 
 	/* GMAC config memory */
-	gmacres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (!gmacres) {
-		dev_err(dev, "no GMAC resource\n");
-		return -ENODEV;
-	}
-	port->gmac_base = devm_ioremap_resource(dev, gmacres);
-	if (IS_ERR(port->gmac_base))
+	port->gmac_base = devm_platform_get_and_ioremap_resource(pdev, 1, &gmacres);
+	if (IS_ERR(port->gmac_base)) {
+		dev_err(dev, "get GMAC address failed\n");
 		return PTR_ERR(port->gmac_base);
+	}
 
 	/* Interrupt */
 	irq = platform_get_irq(pdev, 0);
@@ -2544,17 +2538,13 @@  static int gemini_ethernet_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct gemini_ethernet *geth;
 	unsigned int retry = 5;
-	struct resource *res;
 	u32 val;
 
 	/* Global registers */
 	geth = devm_kzalloc(dev, sizeof(*geth), GFP_KERNEL);
 	if (!geth)
 		return -ENOMEM;
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENODEV;
-	geth->base = devm_ioremap_resource(dev, res);
+	geth->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
 	if (IS_ERR(geth->base))
 		return PTR_ERR(geth->base);
 	geth->dev = dev;