]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: moxa: Use devm_platform_get_and_ioremap_resource()
authorYang Yingliang <yangyingliang@huawei.com>
Mon, 7 Jun 2021 15:02:59 +0000 (23:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Jul 2021 14:10:40 +0000 (16:10 +0200)
commit 35cba15a504bf4f585bb9d78f47b22b28a1a06b2 upstream.

Use devm_platform_get_and_ioremap_resource() to simplify
code and avoid a null-ptr-deref by checking 'res' in it.

[yyl: since devm_platform_get_and_ioremap_resource() is introduced
      in linux-5.7, so just check the return value after calling
      platform_get_resource()]

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/moxa/moxart_ether.c

index f70bb81e1ed652c44242ecd39e7bcf700dcfdb30..caf7051302725b5c32dec05208732636d9465125 100644 (file)
@@ -481,6 +481,10 @@ static int moxart_mac_probe(struct platform_device *pdev)
        priv->pdev = pdev;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               ret = -EINVAL;
+               goto init_fail;
+       }
        ndev->base_addr = res->start;
        priv->base = devm_ioremap_resource(p_dev, res);
        if (IS_ERR(priv->base)) {