net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
Subsystems (3)
PATCH 1/1 net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
In emac_clks_phase1_init() of emac_probe(), there may be a situation in which some clk_prepare_enable() succeed and others fail. If emac_clks_phase1_init() fails, goto err_undo_clocks to clean up the clk that was successfully clk_prepare_enable().
--- drivers/net/ethernet/qualcomm/emac/emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qualcomm/emac/emac.c +1 -1
@@ -628,7 +628,7 @@ static int emac_probe(struct platform_device *pdev) ret =emac_clks_phase1_init (pdev, adpt);if (ret) {dev_err (&pdev->dev,"could not initialize clocks\n" ); - goto err_undo_netdev; + goto err_undo_clocks; } netdev->watchdog_timeo =EMAC_WATCHDOG_TIME ;
Signature · 1 line
2.17.1
Timur Tabi
maintainerQuoted 4 lines · Wang Hai
In
emac_clks_phase1_init()ofemac_probe(), there may be a situation in which someclk_prepare_enable()succeed and others fail. Ifemac_clks_phase1_init()fails, gotoerr_undo_clocksto clean up the clk that was successfullyclk_prepare_enable().
Good catch, however, I think the proper fix is to fix this in emac_clks_phase1_init(), so that if some clocks fail, the other clocks are cleaned up and then an error is returned.
Quoted 10 lines · Timur Tabi
Quoted 4 lines · Wang Hai
In
emac_clks_phase1_init()ofemac_probe(), there may be a situation in which someclk_prepare_enable()succeed and others fail. Ifemac_clks_phase1_init()fails, gotoerr_undo_clocksto clean up the clk that was successfullyclk_prepare_enable().Good catch, however, I think the proper fix is to fix this in
emac_clks_phase1_init(), so that if some clocks fail, the other clocks are cleaned up and then an error is returned..
Thanks for your suggestion. May I fix it like this?
drivers/net/ethernet/qualcomm/emac/emac.c +0 -0
@@ -474,13 +474,25 @@ static int emac_clks_phase1_init(struct platform_device *pdev,
ret = clk_prepare_enable(adpt->clk[EMAC_CLK_CFG_AHB]); if (ret)
- return ret;
+ goto disable_clk_axi;
ret = clk_set_rate(adpt->clk[EMAC_CLK_HIGH_SPEED], 19200000); if (ret)
- return ret;
+ goto disable_clk_cfg_ahb;
- return clk_prepare_enable(adpt->clk[EMAC_CLK_HIGH_SPEED]); + ret = clk_prepare_enable(adpt->clk[EMAC_CLK_HIGH_SPEED]); + if (ret)
+ goto disable_clk_cfg_ahb;
+
+ return 0;
+
+disable_clk_cfg_ahb:
+ clk_disable_unprepare(adpt->clk[EMAC_CLK_CFG_AHB]); +disable_clk_axi:
+ clk_disable_unprepare(adpt->clk[EMAC_CLK_AXI]); +
+ return ret;
}
Quoted 2 lines · wanghai (M)
Thanks for your suggestion. May I fix it like this?
Yes, this is what I had in mind. Thanks.
Quoted 8 lines · Timur Tabi
Quoted 2 lines · wanghai (M)
Thanks for your suggestion. May I fix it like this?
Yes, this is what I had in mind. Thanks.
Acked-by Timur Tabi <[email protected]>.
Thanks for your ack. I just sent a new patch.
"[PATCH net] net: qcom/emac: add missed clk_disable_unprepare in error path of emac_clks_phase1_init"