Skip to content

Commit 5b366ea

Browse files
vmordankuba-moo
authored andcommitted
stmmac: dwmac-intel-plat: fix call balance of tx_clk handling routines
If the clock dwmac->tx_clk was not enabled in intel_eth_plat_probe, it should not be disabled in any path. Conversely, if it was enabled in intel_eth_plat_probe, it must be disabled in all error paths to ensure proper cleanup. Found by Linux Verification Center (linuxtesting.org) with Klever. Fixes: 9efc9b2 ("net: stmmac: Add dwmac-intel-plat for GBE driver") Signed-off-by: Vitalii Mordan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent eb94b7b commit 5b366ea

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
108108
if (IS_ERR(dwmac->tx_clk))
109109
return PTR_ERR(dwmac->tx_clk);
110110

111-
clk_prepare_enable(dwmac->tx_clk);
111+
ret = clk_prepare_enable(dwmac->tx_clk);
112+
if (ret) {
113+
dev_err(&pdev->dev,
114+
"Failed to enable tx_clk\n");
115+
return ret;
116+
}
112117

113118
/* Check and configure TX clock rate */
114119
rate = clk_get_rate(dwmac->tx_clk);
@@ -119,7 +124,7 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
119124
if (ret) {
120125
dev_err(&pdev->dev,
121126
"Failed to set tx_clk\n");
122-
return ret;
127+
goto err_tx_clk_disable;
123128
}
124129
}
125130
}
@@ -133,7 +138,7 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
133138
if (ret) {
134139
dev_err(&pdev->dev,
135140
"Failed to set clk_ptp_ref\n");
136-
return ret;
141+
goto err_tx_clk_disable;
137142
}
138143
}
139144
}
@@ -149,20 +154,24 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
149154
}
150155

151156
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
152-
if (ret) {
153-
clk_disable_unprepare(dwmac->tx_clk);
154-
return ret;
155-
}
157+
if (ret)
158+
goto err_tx_clk_disable;
156159

157160
return 0;
161+
162+
err_tx_clk_disable:
163+
if (dwmac->data->tx_clk_en)
164+
clk_disable_unprepare(dwmac->tx_clk);
165+
return ret;
158166
}
159167

160168
static void intel_eth_plat_remove(struct platform_device *pdev)
161169
{
162170
struct intel_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
163171

164172
stmmac_pltfr_remove(pdev);
165-
clk_disable_unprepare(dwmac->tx_clk);
173+
if (dwmac->data->tx_clk_en)
174+
clk_disable_unprepare(dwmac->tx_clk);
166175
}
167176

168177
static struct platform_driver intel_eth_plat_driver = {

0 commit comments

Comments
 (0)