diff mbox series

[8/8] tty: stm32-usart: Use devm_clk_get_enabled() helpers

Message ID 20240822033924.32397-9-liulei.rjpt@vivo.com (mailing list archive)
State New
Headers show
Series tty serial drivers use devm_clk_get_enabled() helpers | expand

Commit Message

Lei Liu Aug. 22, 2024, 3:39 a.m. UTC
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/stm32-usart.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

Comments

Andy Shevchenko Aug. 22, 2024, 1:23 p.m. UTC | #1
On Thu, Aug 22, 2024 at 11:39:12AM +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().

...

>  err_clk:
> -	clk_disable_unprepare(stm32port->clk);
>  
>  	return ret;

No unneeded label, please drop it as well and return directly.
diff mbox series

Patch

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index e1e7bc04c579..9bce3159165a 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1550,11 +1550,6 @@  static int stm32_usart_get_ftcfg(struct platform_device *pdev, struct stm32_port
 	return fifo_size;
 }
 
-static void stm32_usart_deinit_port(struct stm32_port *stm32port)
-{
-	clk_disable_unprepare(stm32port->clk);
-}
-
 static const struct serial_rs485 stm32_rs485_supported = {
 	.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND |
 		 SER_RS485_RX_DURING_TX,
@@ -1599,15 +1594,10 @@  static int stm32_usart_init_port(struct stm32_port *stm32port,
 
 	spin_lock_init(&port->lock);
 
-	stm32port->clk = devm_clk_get(&pdev->dev, NULL);
+	stm32port->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(stm32port->clk))
 		return PTR_ERR(stm32port->clk);
 
-	/* Ensure that clk rate is correct by enabling the clk */
-	ret = clk_prepare_enable(stm32port->clk);
-	if (ret)
-		return ret;
-
 	stm32port->port.uartclk = clk_get_rate(stm32port->clk);
 	if (!stm32port->port.uartclk) {
 		ret = -EINVAL;
@@ -1645,7 +1635,6 @@  static int stm32_usart_init_port(struct stm32_port *stm32port,
 	return ret;
 
 err_clk:
-	clk_disable_unprepare(stm32port->clk);
 
 	return ret;
 }
@@ -1853,8 +1842,6 @@  static int stm32_usart_serial_probe(struct platform_device *pdev)
 	if (stm32port->wakeup_src)
 		device_set_wakeup_capable(&pdev->dev, false);
 
-	stm32_usart_deinit_port(stm32port);
-
 err_dma_tx:
 	if (stm32port->tx_ch)
 		dma_release_channel(stm32port->tx_ch);
@@ -1904,7 +1891,6 @@  static void stm32_usart_serial_remove(struct platform_device *pdev)
 		device_init_wakeup(&pdev->dev, false);
 	}
 
-	stm32_usart_deinit_port(stm32_port);
 }
 
 static void __maybe_unused stm32_usart_console_putchar(struct uart_port *port, unsigned char ch)