diff mbox series

[3/7] net: macb: unprepare clocks in case of failure

Message ID 1607085261-25255-4-git-send-email-claudiu.beznea@microchip.com
State New
Headers show
Series net: macb: add support for sama7g5 | expand

Commit Message

Claudiu Beznea Dec. 4, 2020, 12:34 p.m. UTC
Unprepare clocks in case of any failure in fu540_c000_clk_init().

Fixes: c218ad559020 ("macb: Add support for SiFive FU540-C000")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/net/ethernet/cadence/macb_main.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Andrew Lunn Dec. 5, 2020, 2:30 p.m. UTC | #1
On Fri, Dec 04, 2020 at 02:34:17PM +0200, Claudiu Beznea wrote:
> Unprepare clocks in case of any failure in fu540_c000_clk_init().


Hi Claudiu

Nice patchset. Simple to understand.
> 


> +err_disable_clocks:

> +	clk_disable_unprepare(*tx_clk);


> +	clk_disable_unprepare(*hclk);

> +	clk_disable_unprepare(*pclk);

> +	clk_disable_unprepare(*rx_clk);

> +	clk_disable_unprepare(*tsu_clk);


This looks correct, but it would be more symmetrical to add a

macb_clk_uninit()

function for the four main clocks. I'm surprised it does not already
exist.

	Andrew
Claudiu Beznea Dec. 7, 2020, 9:26 a.m. UTC | #2
Hi Andrew,

On 05.12.2020 16:30, Andrew Lunn wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

> 

> On Fri, Dec 04, 2020 at 02:34:17PM +0200, Claudiu Beznea wrote:

>> Unprepare clocks in case of any failure in fu540_c000_clk_init().

> 

> Hi Claudiu

> 

> Nice patchset. Simple to understand.

>>

> 

>> +err_disable_clocks:

>> +     clk_disable_unprepare(*tx_clk);

> 

>> +     clk_disable_unprepare(*hclk);

>> +     clk_disable_unprepare(*pclk);

>> +     clk_disable_unprepare(*rx_clk);

>> +     clk_disable_unprepare(*tsu_clk);

> 

> This looks correct, but it would be more symmetrical to add a

> 

> macb_clk_uninit()

> 

> function for the four main clocks. I'm surprised it does not already

> exist.


I was in balance b/w added and not added it taking into account that the
disable unprepares are not taking care of all the clocks, in all the
places, in the same way. Anyway, I will add one function for the main
clocks, as you proposed, in the next version.

Thank you for your review,
Claudiu

> 

>         Andrew

>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index b23e986ac6dc..29d144690b3b 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4406,8 +4406,10 @@  static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,
 		return err;
 
 	mgmt = devm_kzalloc(&pdev->dev, sizeof(*mgmt), GFP_KERNEL);
-	if (!mgmt)
-		return -ENOMEM;
+	if (!mgmt) {
+		err = -ENOMEM;
+		goto err_disable_clocks;
+	}
 
 	init.name = "sifive-gemgxl-mgmt";
 	init.ops = &fu540_c000_ops;
@@ -4418,16 +4420,29 @@  static int fu540_c000_clk_init(struct platform_device *pdev, struct clk **pclk,
 	mgmt->hw.init = &init;
 
 	*tx_clk = devm_clk_register(&pdev->dev, &mgmt->hw);
-	if (IS_ERR(*tx_clk))
-		return PTR_ERR(*tx_clk);
+	if (IS_ERR(*tx_clk)) {
+		err = PTR_ERR(*tx_clk);
+		goto err_disable_clocks;
+	}
 
 	err = clk_prepare_enable(*tx_clk);
-	if (err)
+	if (err) {
 		dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err);
-	else
+		goto err_disable_clocks;
+	} else {
 		dev_info(&pdev->dev, "Registered clk switch '%s'\n", init.name);
+	}
 
 	return 0;
+
+err_disable_clocks:
+	clk_disable_unprepare(*tx_clk);
+	clk_disable_unprepare(*hclk);
+	clk_disable_unprepare(*pclk);
+	clk_disable_unprepare(*rx_clk);
+	clk_disable_unprepare(*tsu_clk);
+
+	return err;
 }
 
 static int fu540_c000_init(struct platform_device *pdev)