Skip to contentSkip to conversation

serial: imx: Fix clock imbalance

PATCH In review Marek Vasut 4 participants 4 messages Dec 5, 2023 – Dec 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: imx: Fix clock imbalance

Disable and unprepare the clock on every exit from probe function after the clock were prepared and enabled to avoid enable/disable imbalance.

---
Cc: "Ilpo Järvinen" <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Sergey Organov <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tom Rix <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/tty/serial/imx.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/tty/serial/imx.c +10 -8
index 52dd8a6b87603..1cce66e5d05d8 100644
@@ -2332,10 +2332,8 @@ static int imx_uart_probe(struct platform_device *pdev)
 	}
 
 	ret = uart_get_rs485_mode(&sport->port);
-	if (ret) {
-		clk_disable_unprepare(sport->clk_ipg);
-		return ret;
-	}
+	if (ret)
+		goto err_clk;
 
 	if (sport->port.rs485.flags & SER_RS485_ENABLED &&
 	    (!sport->have_rtscts && !sport->have_rtsgpio))
@@ -2436,7 +2434,7 @@ static int imx_uart_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request rx irq: %d\n",
 				ret);
-			return ret;
+			goto err_clk;
 		}
 
 		ret = devm_request_irq(&pdev->dev, txirq, imx_uart_txint, 0,
@@ -2444,7 +2442,7 @@ static int imx_uart_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request tx irq: %d\n",
 				ret);
-			return ret;
+			goto err_clk;
 		}
 
 		ret = devm_request_irq(&pdev->dev, rtsirq, imx_uart_rtsint, 0,
@@ -2452,14 +2450,14 @@ static int imx_uart_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request rts irq: %d\n",
 				ret);
-			return ret;
+			goto err_clk;
 		}
 	} else {
 		ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_int, 0,
 				       dev_name(&pdev->dev), sport);
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
-			return ret;
+			goto err_clk;
 		}
 	}
 
@@ -2468,6 +2466,10 @@ static int imx_uart_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, sport);
 
 	return uart_add_one_port(&imx_uart_uart_driver, &sport->port);
+
+err_clk:
+	clk_disable_unprepare(sport->clk_ipg);
+	return ret;
 }
 
 static void imx_uart_remove(struct platform_device *pdev)
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Marek Vasut

From: linux-arm-kernel [mailto:[email protected]] On Behalf Of Marek Vasut
Sent: Tuesday, December 5, 2023 1:51 AM

Quoted 78 lines

Disable and unprepare the clock on every exit from probe function after the clock were prepared and enabled to avoid enable/disable imbalance.

---
Cc: "Ilpo Järvinen" <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Sergey Organov <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tom Rix <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/tty/serial/imx.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/tty/serial/imx.c +6 -8
index 52dd8a6b87603..1cce66e5d05d8 100644
@@ -2332,10 +2332,8 @@ static int imx_uart_probe(struct platform_device *pdev)
        }
 
        ret = uart_get_rs485_mode(&sport->port);
-       if (ret) {
-               clk_disable_unprepare(sport->clk_ipg);
-               return ret;
-       }
+       if (ret)
+               goto err_clk;
 
        if (sport->port.rs485.flags & SER_RS485_ENABLED &&
            (!sport->have_rtscts && !sport->have_rtsgpio))
@@ -2436,7 +2434,7 @@ static int imx_uart_probe(struct platform_device *pdev)
                if (ret) {
                        dev_err(&pdev->dev, "failed to request rx irq: %d\n",
                                ret);
-                       return ret;
+                       goto err_clk;
                }
 
                ret = devm_request_irq(&pdev->dev, txirq, imx_uart_txint, 0,
@@ -2444,7 +2442,7 @@ static int imx_uart_probe(struct platform_device *pdev)
                if (ret) {
                        dev_err(&pdev->dev, "failed to request tx irq: %d\n",
                                ret);
-                       return ret;
+                       goto err_clk;
                }
 
                ret = devm_request_irq(&pdev->dev, rtsirq, imx_uart_rtsint, 0,
@@ -2452,14 +2450,14 @@ static int imx_uart_probe(struct platform_device *pdev)
                if (ret) {
                        dev_err(&pdev->dev, "failed to request rts irq: %d\n",
                                ret);
-                       return ret;
+                       goto err_clk;
                }
        } else {
                ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_int, 0,
                                       dev_name(&pdev->dev), sport);
                if (ret) {
                        dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
-                       return ret;
+                       goto err_clk;
                }
        }
 

drivers/tty/serial/imx.c static int imx_uart_probe(struct platform_device *pdev) · line 2475

Quoted 10 lines
drivers/tty/serial/imx.c +4 -0
@@ -2468,6 +2466,10 @@ static int imx_uart_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, sport);
 
        return uart_add_one_port(&imx_uart_uart_driver, &sport->port);
+
+err_clk:
+       clk_disable_unprepare(sport->clk_ipg);
+       return ret;
 }
 
 static void imx_uart_remove(struct platform_device *pdev)

Regards
Christoph

#3 lore raw
In reply to Marek Vasut

Hello Marek,

Quoted 3 lines · Marek Vasut

Disable and unprepare the clock on every exit from probe function after the clock were prepared and enabled to avoid enable/disable imbalance.

Why not switch the probe function to use devm_clk_get_enabled() instead?

Cheers,
Ahmad

Quoted 85 lines

---
Cc: "Ilpo Järvinen" <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Sergey Organov <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tom Rix <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/tty/serial/imx.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/tty/serial/imx.c +10 -8
index 52dd8a6b87603..1cce66e5d05d8 100644
@@ -2332,10 +2332,8 @@ static int imx_uart_probe(struct platform_device *pdev)
 	}
 
 	ret = uart_get_rs485_mode(&sport->port);
-	if (ret) {
-		clk_disable_unprepare(sport->clk_ipg);
-		return ret;
-	}
+	if (ret)
+		goto err_clk;
 
 	if (sport->port.rs485.flags & SER_RS485_ENABLED &&
 	    (!sport->have_rtscts && !sport->have_rtsgpio))
@@ -2436,7 +2434,7 @@ static int imx_uart_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request rx irq: %d\n",
 				ret);
-			return ret;
+			goto err_clk;
 		}
 
 		ret = devm_request_irq(&pdev->dev, txirq, imx_uart_txint, 0,
@@ -2444,7 +2442,7 @@ static int imx_uart_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request tx irq: %d\n",
 				ret);
-			return ret;
+			goto err_clk;
 		}
 
 		ret = devm_request_irq(&pdev->dev, rtsirq, imx_uart_rtsint, 0,
@@ -2452,14 +2450,14 @@ static int imx_uart_probe(struct platform_device *pdev)
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request rts irq: %d\n",
 				ret);
-			return ret;
+			goto err_clk;
 		}
 	} else {
 		ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_int, 0,
 				       dev_name(&pdev->dev), sport);
 		if (ret) {
 			dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
-			return ret;
+			goto err_clk;
 		}
 	}
 
@@ -2468,6 +2466,10 @@ static int imx_uart_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, sport);
 
 	return uart_add_one_port(&imx_uart_uart_driver, &sport->port);
+
+err_clk:
+	clk_disable_unprepare(sport->clk_ipg);
+	return ret;
 }
 
 static void imx_uart_remove(struct platform_device *pdev)
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |