net: davinci_emac: Use devm_platform_get_and_ioremap_resource()
authorYang Yingliang <yangyingliang@huawei.com>
Wed, 9 Jun 2021 14:17:44 +0000 (22:17 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 10 Jun 2021 20:02:01 +0000 (13:02 -0700)
Use devm_platform_get_and_ioremap_resource() to simplify
code and avoid a null-ptr-deref by checking 'res' in it.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/davinci_emac.c

index f9417b4..c674e34 100644 (file)
@@ -1814,13 +1814,12 @@ static int davinci_emac_probe(struct platform_device *pdev)
        priv->bus_freq_mhz = (u32)(emac_bus_frequency / 1000000);
 
        /* Get EMAC platform data */
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       priv->emac_base_phys = res->start + pdata->ctrl_reg_offset;
-       priv->remap_addr = devm_ioremap_resource(&pdev->dev, res);
+       priv->remap_addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
        if (IS_ERR(priv->remap_addr)) {
                rc = PTR_ERR(priv->remap_addr);
                goto no_pdata;
        }
+       priv->emac_base_phys = res->start + pdata->ctrl_reg_offset;
 
        res_ctrl = platform_get_resource(pdev, IORESOURCE_MEM, 1);
        if (res_ctrl) {