linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] phy: phy-mtk-tphy: fix missing clk_disable_unprepare() on error in mtk_phy_init()
@ 2018-03-20 13:19 Wei Yongjun
  2018-03-21  3:04 ` Chunfeng Yun
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2018-03-20 13:19 UTC (permalink / raw)
  To: linux-arm-kernel

Fix the missing clk_disable_unprepare() before return
from mtk_phy_init() in the error handling case.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/phy/mediatek/phy-mtk-tphy.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c
index 38c281b..3ff9020 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -841,7 +841,7 @@ static int mtk_phy_init(struct phy *phy)
 	ret = clk_prepare_enable(instance->ref_clk);
 	if (ret) {
 		dev_err(tphy->dev, "failed to enable ref_clk\n");
-		return ret;
+		goto disable_u3phya_ref;
 	}
 
 	switch (instance->type) {
@@ -859,10 +859,17 @@ static int mtk_phy_init(struct phy *phy)
 		break;
 	default:
 		dev_err(tphy->dev, "incompatible PHY type\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto disable_ref_clk;
 	}
 
 	return 0;
+
+disable_ref_clk:
+	clk_disable_unprepare(instance->ref_clk);
+disable_u3phya_ref:
+	clk_disable_unprepare(tphy->u3phya_ref);
+	return ret;
 }
 
 static int mtk_phy_power_on(struct phy *phy)

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

* [PATCH -next] phy: phy-mtk-tphy: fix missing clk_disable_unprepare() on error in mtk_phy_init()
  2018-03-20 13:19 [PATCH -next] phy: phy-mtk-tphy: fix missing clk_disable_unprepare() on error in mtk_phy_init() Wei Yongjun
@ 2018-03-21  3:04 ` Chunfeng Yun
  0 siblings, 0 replies; 2+ messages in thread
From: Chunfeng Yun @ 2018-03-21  3:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 2018-03-20 at 13:19 +0000, Wei Yongjun wrote:
> Fix the missing clk_disable_unprepare() before return
> from mtk_phy_init() in the error handling case.
> 
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  drivers/phy/mediatek/phy-mtk-tphy.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c
> index 38c281b..3ff9020 100644
> --- a/drivers/phy/mediatek/phy-mtk-tphy.c
> +++ b/drivers/phy/mediatek/phy-mtk-tphy.c
> @@ -841,7 +841,7 @@ static int mtk_phy_init(struct phy *phy)
>  	ret = clk_prepare_enable(instance->ref_clk);
>  	if (ret) {
>  		dev_err(tphy->dev, "failed to enable ref_clk\n");
> -		return ret;
> +		goto disable_u3phya_ref;
@u3phya_ref and @ref_clk clocks are mutually exclusive, that means one
of them must be NULL; so if failed to enable @ref_clk, then @u3phya_ref
should be NULL, and no need to disable it in fact.
But it's also no problem to disable it.
>  	}


>  
>  	switch (instance->type) {
> @@ -859,10 +859,17 @@ static int mtk_phy_init(struct phy *phy)
>  		break;
>  	default:
>  		dev_err(tphy->dev, "incompatible PHY type\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto disable_ref_clk;
mtk_phy_xlate() has already checked supported type,so usually doesn't
comes here, otherwise there will be a serious problem about system.

Anyway, it's better to disable these clocks when fail.
>  	}
>  
>  	return 0;
> +
> +disable_ref_clk:
> +	clk_disable_unprepare(instance->ref_clk);
> +disable_u3phya_ref:
> +	clk_disable_unprepare(tphy->u3phya_ref);
> +	return ret;
>  }
>  
>  static int mtk_phy_power_on(struct phy *phy)
> 
Tested-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Acked-by: Chunfeng Yun <chunfeng.yun@mediatek.com>

Thanks a lot
> 
> 

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

end of thread, other threads:[~2018-03-21  3:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-20 13:19 [PATCH -next] phy: phy-mtk-tphy: fix missing clk_disable_unprepare() on error in mtk_phy_init() Wei Yongjun
2018-03-21  3:04 ` Chunfeng Yun

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