net: stmicro: handle clk_prepare() failure during init
authorAnirudh Rayabharam <mail@anirudhrb.com>
Mon, 3 May 2021 11:56:48 +0000 (13:56 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 May 2021 09:47:01 +0000 (11:47 +0200)
commit 0c32a96d000f260b5ebfabb4145a86ae1cd71847 upstream.

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: Anirudh 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.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c

index c0824c6fe86de5dde0f949953b3a740de86a1bc5..f31067659e95f43f2b6002d6955834401de2c356 100644 (file)
@@ -39,7 +39,7 @@ struct sunxi_priv_data {
 static int sun7i_gmac_init(struct platform_device *pdev, void *priv)
 {
        struct sunxi_priv_data *gmac = priv;
-       int ret;
+       int ret = 0;
 
        if (gmac->regulator) {
                ret = regulator_enable(gmac->regulator);
@@ -59,10 +59,12 @@ static int sun7i_gmac_init(struct platform_device *pdev, void *priv)
                gmac->clk_enabled = 1;
        } else {
                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)