lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20240826113337.7364-1-liulei.rjpt@vivo.com>
Date: Mon, 26 Aug 2024 19:33:34 +0800
From: Lei Liu <liulei.rjpt@...o.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Jiri Slaby <jirislaby@...nel.org>,
	Maxime Coquelin <mcoquelin.stm32@...il.com>,
	Alexandre Torgue <alexandre.torgue@...s.st.com>,
	Valentin Caron <valentin.caron@...s.st.com>,
	Uwe Kleine-König <u.kleine-koenig@...gutronix.de>,
	Lino Sanfilippo <l.sanfilippo@...bus.com>,
	Erwan Le Ray <erwan.leray@...s.st.com>,
	Lei Liu <liulei.rjpt@...o.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	linux-kernel@...r.kernel.org,
	linux-serial@...r.kernel.org,
	linux-stm32@...md-mailman.stormreply.com,
	linux-arm-kernel@...ts.infradead.org
Cc: opensource.kernel@...o.com
Subject: [PATCH v2 5/5] tty: stm32-usart: Use devm_clk_get_enabled() helpers

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().

---
v1->V2 changes
1.stm32-usart modifies the return method and removes unused labels

Signed-off-by: Lei Liu <liulei.rjpt@...o.com>
---
 drivers/tty/serial/stm32-usart.c | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index e1e7bc04c579..559fcc2659eb 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,19 +1594,13 @@ 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;
-		goto err_clk;
+		return -EINVAL;
 	}
 
 	stm32port->fifoen = stm32port->info->cfg.has_fifo;
@@ -1625,8 +1614,7 @@ static int stm32_usart_init_port(struct stm32_port *stm32port,
 
 	stm32port->gpios = mctrl_gpio_init(&stm32port->port, 0);
 	if (IS_ERR(stm32port->gpios)) {
-		ret = PTR_ERR(stm32port->gpios);
-		goto err_clk;
+		return PTR_ERR(stm32port->gpios);
 	}
 
 	/*
@@ -1637,16 +1625,9 @@ static int stm32_usart_init_port(struct stm32_port *stm32port,
 		if (mctrl_gpio_to_gpiod(stm32port->gpios, UART_GPIO_CTS) ||
 		    mctrl_gpio_to_gpiod(stm32port->gpios, UART_GPIO_RTS)) {
 			dev_err(&pdev->dev, "Conflicting RTS/CTS config\n");
-			ret = -EINVAL;
-			goto err_clk;
+			return -EINVAL;
 		}
 	}
-
-	return ret;
-
-err_clk:
-	clk_disable_unprepare(stm32port->clk);
-
 	return ret;
 }
 
@@ -1853,8 +1834,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 +1883,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)
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ