OSDN Git Service

net: mido: mdio-mux-bcm-iproc: Use devm_platform_get_and_ioremap_resource()
authorYang Yingliang <yangyingliang@huawei.com>
Thu, 10 Jun 2021 09:17:12 +0000 (17:17 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 10 Jun 2021 20:59:37 +0000 (13:59 -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/mdio/mdio-mux-bcm-iproc.c

index 239e88c..014c0ba 100644 (file)
@@ -187,7 +187,9 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev)
                return -ENOMEM;
        md->dev = &pdev->dev;
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       md->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+       if (IS_ERR(md->base))
+               return PTR_ERR(md->base);
        if (res->start & 0xfff) {
                /* For backward compatibility in case the
                 * base address is specified with an offset.
@@ -196,9 +198,6 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev)
                res->start &= ~0xfff;
                res->end = res->start + MDIO_REG_ADDR_SPACE_SIZE - 1;
        }
-       md->base = devm_ioremap_resource(&pdev->dev, res);
-       if (IS_ERR(md->base))
-               return PTR_ERR(md->base);
 
        md->mii_bus = devm_mdiobus_alloc(&pdev->dev);
        if (!md->mii_bus) {