Commit 0c32a96d authored by Anirudh Rayabharam's avatar Anirudh Rayabharam Committed by Greg Kroah-Hartman

net: stmicro: handle clk_prepare() failure during init

In case clk_prepare() fails, capture and propagate the error code up the
stack. If regulator_enable() was called earlier, properly unwind it by
calling regulator_disable().
Signed-off-by: default avatarAnirudh Rayabharam <mail@anirudhrb.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210503115736.2104747-22-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bee1b051
...@@ -30,7 +30,7 @@ struct sunxi_priv_data { ...@@ -30,7 +30,7 @@ struct sunxi_priv_data {
static int sun7i_gmac_init(struct platform_device *pdev, void *priv) static int sun7i_gmac_init(struct platform_device *pdev, void *priv)
{ {
struct sunxi_priv_data *gmac = priv; struct sunxi_priv_data *gmac = priv;
int ret; int ret = 0;
if (gmac->regulator) { if (gmac->regulator) {
ret = regulator_enable(gmac->regulator); ret = regulator_enable(gmac->regulator);
...@@ -50,10 +50,12 @@ static int sun7i_gmac_init(struct platform_device *pdev, void *priv) ...@@ -50,10 +50,12 @@ static int sun7i_gmac_init(struct platform_device *pdev, void *priv)
gmac->clk_enabled = 1; gmac->clk_enabled = 1;
} else { } else {
clk_set_rate(gmac->tx_clk, SUN7I_GMAC_MII_RATE); clk_set_rate(gmac->tx_clk, SUN7I_GMAC_MII_RATE);
clk_prepare(gmac->tx_clk); ret = clk_prepare(gmac->tx_clk);
if (ret && gmac->regulator)
regulator_disable(gmac->regulator);
} }
return 0; return ret;
} }
static void sun7i_gmac_exit(struct platform_device *pdev, void *priv) static void sun7i_gmac_exit(struct platform_device *pdev, void *priv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment