stmmac: intel: Fix clock handling on error and remove paths
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 30 Apr 2020 15:02:49 +0000 (18:02 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 30 Apr 2020 19:50:15 +0000 (12:50 -0700)
clk_prepare_enable() might fail, we have to check its returned value.
Besides that we have to call clk_disable_unprepare() on the error and
remove paths. Do above in the dwmac-intel driver.

While at it, remove leftover in stmmac_pci and remove unneeded condition
for NULL-aware clk_unregister_fixed_rate() call.

Fixes: 58da0cfa6cf1 ("net: stmmac: create dwmac-intel.c to contain all Intel platform")
Cc: Voon Weifeng <weifeng.voon@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/dwmac-intel.c
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c

index 2e4aaedb93f58098fa1e68fe364464d1e3eae325..d163c4b43da0fd5ee0d347d143790e1e6c4db8e2 100644 (file)
@@ -252,6 +252,7 @@ static void common_default_data(struct plat_stmmacenet_data *plat)
 static int intel_mgbe_common_data(struct pci_dev *pdev,
                                  struct plat_stmmacenet_data *plat)
 {
+       int ret;
        int i;
 
        plat->clk_csr = 5;
@@ -324,7 +325,12 @@ static int intel_mgbe_common_data(struct pci_dev *pdev,
                dev_warn(&pdev->dev, "Fail to register stmmac-clk\n");
                plat->stmmac_clk = NULL;
        }
-       clk_prepare_enable(plat->stmmac_clk);
+
+       ret = clk_prepare_enable(plat->stmmac_clk);
+       if (ret) {
+               clk_unregister_fixed_rate(plat->stmmac_clk);
+               return ret;
+       }
 
        /* Set default value for multicast hash bins */
        plat->multicast_filter_bins = HASH_TABLE_SIZE;
@@ -657,7 +663,13 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
        res.wol_irq = pdev->irq;
        res.irq = pdev->irq;
 
-       return stmmac_dvr_probe(&pdev->dev, plat, &res);
+       ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
+       if (ret) {
+               clk_disable_unprepare(plat->stmmac_clk);
+               clk_unregister_fixed_rate(plat->stmmac_clk);
+       }
+
+       return ret;
 }
 
 /**
@@ -675,8 +687,8 @@ static void intel_eth_pci_remove(struct pci_dev *pdev)
 
        stmmac_dvr_remove(&pdev->dev);
 
-       if (priv->plat->stmmac_clk)
-               clk_unregister_fixed_rate(priv->plat->stmmac_clk);
+       clk_disable_unprepare(priv->plat->stmmac_clk);
+       clk_unregister_fixed_rate(priv->plat->stmmac_clk);
 
        for (i = 0; i < PCI_STD_NUM_BARS; i++) {
                if (pci_resource_len(pdev, i) == 0)
index 3fb21f7ac9fbeeeac765b56e069c2d106850615d..272cb47af9f2eac5a6c0ad36c5e174c0411107f4 100644 (file)
@@ -217,15 +217,10 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
  */
 static void stmmac_pci_remove(struct pci_dev *pdev)
 {
-       struct net_device *ndev = dev_get_drvdata(&pdev->dev);
-       struct stmmac_priv *priv = netdev_priv(ndev);
        int i;
 
        stmmac_dvr_remove(&pdev->dev);
 
-       if (priv->plat->stmmac_clk)
-               clk_unregister_fixed_rate(priv->plat->stmmac_clk);
-
        for (i = 0; i < PCI_STD_NUM_BARS; i++) {
                if (pci_resource_len(pdev, i) == 0)
                        continue;