net: ftgmac100: add missing error return code in ftgmac100_probe()
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 22 May 2021 12:02:46 +0000 (20:02 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 23 May 2021 23:16:24 +0000 (16:16 -0700)
The variables will be free on path err_phy_connect, it should
return error code, or it will cause double free when calling
ftgmac100_remove().

Fixes: bd466c3fb5a4 ("net/faraday: Support NCSI mode")
Fixes: 39bfab8844a0 ("net: ftgmac100: Add support for DT phy-handle property")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/faraday/ftgmac100.c

index 04421ae..11dbbfd 100644 (file)
@@ -1830,14 +1830,17 @@ static int ftgmac100_probe(struct platform_device *pdev)
        if (np && of_get_property(np, "use-ncsi", NULL)) {
                if (!IS_ENABLED(CONFIG_NET_NCSI)) {
                        dev_err(&pdev->dev, "NCSI stack not enabled\n");
        if (np && of_get_property(np, "use-ncsi", NULL)) {
                if (!IS_ENABLED(CONFIG_NET_NCSI)) {
                        dev_err(&pdev->dev, "NCSI stack not enabled\n");
+                       err = -EINVAL;
                        goto err_phy_connect;
                }
 
                dev_info(&pdev->dev, "Using NCSI interface\n");
                priv->use_ncsi = true;
                priv->ndev = ncsi_register_dev(netdev, ftgmac100_ncsi_handler);
                        goto err_phy_connect;
                }
 
                dev_info(&pdev->dev, "Using NCSI interface\n");
                priv->use_ncsi = true;
                priv->ndev = ncsi_register_dev(netdev, ftgmac100_ncsi_handler);
-               if (!priv->ndev)
+               if (!priv->ndev) {
+                       err = -EINVAL;
                        goto err_phy_connect;
                        goto err_phy_connect;
+               }
        } else if (np && of_get_property(np, "phy-handle", NULL)) {
                struct phy_device *phy;
 
        } else if (np && of_get_property(np, "phy-handle", NULL)) {
                struct phy_device *phy;
 
@@ -1856,6 +1859,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
                                             &ftgmac100_adjust_link);
                if (!phy) {
                        dev_err(&pdev->dev, "Failed to connect to phy\n");
                                             &ftgmac100_adjust_link);
                if (!phy) {
                        dev_err(&pdev->dev, "Failed to connect to phy\n");
+                       err = -EINVAL;
                        goto err_phy_connect;
                }
 
                        goto err_phy_connect;
                }