linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "wanghai (M)" <wanghai38@huawei.com>
To: Timur Tabi <timur@kernel.org>, <davem@davemloft.net>, <kuba@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>
Subject: Re: [PATCH net] net: qcom/emac: Fix missing clk_disable_unprepare() in error path of emac_probe
Date: Fri, 7 Aug 2020 09:54:46 +0800	[thread overview]
Message-ID: <df1bad2e-2a6a-ff70-9b91-f18df20aaec8@huawei.com> (raw)
In-Reply-To: <87f41175-689e-f198-aaf6-9b9f04449ed8@kernel.org>


在 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;
  }



  reply	other threads:[~2020-08-07  1:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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) [this message]
2020-08-07 13:38     ` Timur Tabi
2020-08-10  3:01       ` wanghai (M)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df1bad2e-2a6a-ff70-9b91-f18df20aaec8@huawei.com \
    --to=wanghai38@huawei.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=timur@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).