All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
@ 2020-08-06 14:06 Wang Hai
  2020-08-06 14:23 ` Timur Tabi
  0 siblings, 1 reply; 5+ messages in thread
From: Wang Hai @ 2020-08-06 14:06 UTC (permalink / raw)
  To: timur, davem, kuba; +Cc: linux-kernel, netdev

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().

Fixes: b9b17debc69d ("net: emac: emac gigabit ethernet controller driver")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 drivers/net/ethernet/qualcomm/emac/emac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c b/drivers/net/ethernet/qualcomm/emac/emac.c
index 20b1b43a0e39..7520c02eec12 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
  2020-08-06 14:06 [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe Wang Hai
@ 2020-08-06 14:23 ` Timur Tabi
  2020-08-07  1:54   ` wanghai (M)
  0 siblings, 1 reply; 5+ messages in thread
From: Timur Tabi @ 2020-08-06 14:23 UTC (permalink / raw)
  To: Wang Hai, davem, kuba; +Cc: linux-kernel, netdev

On 8/6/20 9:06 AM, Wang Hai wrote:
> 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().

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
  2020-08-06 14:23 ` Timur Tabi
@ 2020-08-07  1:54   ` wanghai (M)
  2020-08-07 13:38     ` Timur Tabi
  0 siblings, 1 reply; 5+ messages in thread
From: wanghai (M) @ 2020-08-07  1:54 UTC (permalink / raw)
  To: Timur Tabi, davem, kuba; +Cc: linux-kernel, netdev


在 2020/8/6 22:23, Timur Tabi 写道:
> On 8/6/20 9:06 AM, Wang Hai wrote:
>> 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().
>
> 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?

diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c 
b/drivers/net/ethernet/qualcomm/emac/emac.c
index 7520c02eec12..7977ad02a7c6 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -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;
  }



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
  2020-08-07  1:54   ` wanghai (M)
@ 2020-08-07 13:38     ` Timur Tabi
  2020-08-10  3:01       ` wanghai (M)
  0 siblings, 1 reply; 5+ messages in thread
From: Timur Tabi @ 2020-08-07 13:38 UTC (permalink / raw)
  To: wanghai (M), davem, kuba; +Cc: linux-kernel, netdev

On 8/6/20 8:54 PM, wanghai (M) wrote:
> Thanks for your suggestion. May I fix it like this?
> 
Yes, this is what I had in mind.  Thanks.

Acked-by: Timur Tabi <timur@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
  2020-08-07 13:38     ` Timur Tabi
@ 2020-08-10  3:01       ` wanghai (M)
  0 siblings, 0 replies; 5+ messages in thread
From: wanghai (M) @ 2020-08-10  3:01 UTC (permalink / raw)
  To: Timur Tabi, davem, kuba; +Cc: linux-kernel, netdev


在 2020/8/7 21:38, Timur Tabi 写道:
> On 8/6/20 8:54 PM, wanghai (M) wrote:
>> Thanks for your suggestion. May I fix it like this?
>>
> Yes, this is what I had in mind.  Thanks.
>
> Acked-by: Timur Tabi <timur@kernel.org>
>
> .

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"



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-10  3:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 14:06 [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe Wang Hai
2020-08-06 14:23 ` Timur Tabi
2020-08-07  1:54   ` wanghai (M)
2020-08-07 13:38     ` Timur Tabi
2020-08-10  3:01       ` wanghai (M)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.