stmmac: intel: Fix kernel crash due to wrong error path
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 29 Apr 2020 15:09:32 +0000 (18:09 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 May 2020 04:00:17 +0000 (21:00 -0700)
Unfortunately sometimes ->probe() may fail. The commit b9663b7ca6ff
("net: stmmac: Enable SERDES power up/down sequence")
messed up with error handling and thus:

[   12.811311] ------------[ cut here ]------------
[   12.811993] kernel BUG at net/core/dev.c:9937!

Fix this by properly crafted error path.

Fixes: b9663b7ca6ff ("net: stmmac: Enable SERDES power up/down sequence")
Cc: Voon Weifeng <weifeng.voon@intel.com>
Cc: Ong Boon Leong <boon.leong.ong@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index 565da6498c846eac02648dd0c9da946431f58b5c..ff22f274aa43d60bd15c91e3b6ab5017dac92d4e 100644 (file)
@@ -4991,7 +4991,7 @@ int stmmac_dvr_probe(struct device *device,
                                                 priv->plat->bsp_priv);
 
                if (ret < 0)
-                       return ret;
+                       goto error_serdes_powerup;
        }
 
 #ifdef CONFIG_DEBUG_FS
@@ -5000,6 +5000,8 @@ int stmmac_dvr_probe(struct device *device,
 
        return ret;
 
+error_serdes_powerup:
+       unregister_netdev(ndev);
 error_netdev_register:
        phylink_destroy(priv->phylink);
 error_phy_setup: