Skip to content

Commit

Permalink
stmmac: intel: Fix clock handling on error and remove paths
Browse files Browse the repository at this point in the history
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: 58da0cf ("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>
  • Loading branch information
Andy Shevchenko authored and David S. Miller committed Apr 30, 2020
1 parent 801eb05 commit 09f012e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 16 additions & 4 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 09f012e

Please sign in to comment.