[PATCH 7/8] tty: st-asc: Use devm_clk_get_enabled() helpers

Lei Liu posted 8 patches 1 year, 5 months ago
[PATCH 7/8] tty: st-asc: Use devm_clk_get_enabled() helpers
Posted by Lei Liu 1 year, 5 months ago
The devm_clk_get_enabled() helpers:
    - call devm_clk_get()
    - call clk_prepare_enable() and register what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids calls to clk_disable_unprepare().

Signed-off-by: Lei Liu <liulei.rjpt@vivo.com>
---
 drivers/tty/serial/st-asc.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index f91753a40a69..df666766d50e 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -706,17 +706,13 @@ static int asc_init_port(struct asc_port *ascport,
 
 	spin_lock_init(&port->lock);
 
-	ascport->clk = devm_clk_get(&pdev->dev, NULL);
+	ascport->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 
 	if (WARN_ON(IS_ERR(ascport->clk)))
 		return -EINVAL;
-	/* ensure that clk rate is correct by enabling the clk */
-	ret = clk_prepare_enable(ascport->clk);
-	if (ret)
-		return ret;
+
 	ascport->port.uartclk = clk_get_rate(ascport->clk);
 	WARN_ON(ascport->port.uartclk == 0);
-	clk_disable_unprepare(ascport->clk);
 
 	ascport->pinctrl = devm_pinctrl_get(&pdev->dev);
 	if (IS_ERR(ascport->pinctrl)) {
-- 
2.34.1
Re: [PATCH 7/8] tty: st-asc: Use devm_clk_get_enabled() helpers
Posted by Andy Shevchenko 1 year, 5 months ago
On Thu, Aug 22, 2024 at 11:39:11AM +0800, Lei Liu wrote:
> The devm_clk_get_enabled() helpers:
>     - call devm_clk_get()
>     - call clk_prepare_enable() and register what is needed in order to
>      call clk_disable_unprepare() when needed, as a managed resource.
> 
> This simplifies the code and avoids calls to clk_disable_unprepare().

...

Same caveat as in another patch comment.

> -	ascport->clk = devm_clk_get(&pdev->dev, NULL);
> +	ascport->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  
>  	if (WARN_ON(IS_ERR(ascport->clk)))
>  		return -EINVAL;
> -	/* ensure that clk rate is correct by enabling the clk */
> -	ret = clk_prepare_enable(ascport->clk);
> -	if (ret)
> -		return ret;
> +
>  	ascport->port.uartclk = clk_get_rate(ascport->clk);

>  	WARN_ON(ascport->port.uartclk == 0);

Btw, not related to this series, you may try to get rid of these 0 checks as
the serial core has this and it will fail anyway. Perhaps you want to expand
serial core to issue an error message (if it's not done yet).

> -	clk_disable_unprepare(ascport->clk);

-- 
With Best Regards,
Andy Shevchenko