[PATCH 22/24] serial: samsung: put the previous baud clock

From: Greg Kroah-Hartman

Date: Tue Oct 27 2026 - 07:19:04 EST


From: Josef Bacik <josef@xxxxxxxxxxxxxx>

s3c24xx_serial_getclk() returns the best baud clock with the reference
which clk_get() has taken. s3c24xx_serial_set_termios() stores it in
ourport->baudclk and disables the clock which was there before, but does
not put it.

clk_get() hands out a new handle on every call, so the new clock never
equals the old one, and every call of ->set_termios() leaks a handle: a
struct clk and a copy of the connection name. Whoever has the port open
can repeat that at will with tcsetattr().

Put the old clock when it is replaced, and the new one in case it is not
stored.

Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Cc: stable <stable@xxxxxxxxxx>
Cc: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Cc: Peter Griffin <peter.griffin@xxxxxxxxxx>
Cc: Alim Akhtar <alim.akhtar@xxxxxxxxxxx>
Cc: Jiri Slaby <jirislaby@xxxxxxxxxx>
Cc: Kukjin Kim <kgene.kim@xxxxxxxxxxx>
Cc: Thomas Abraham <thomas.abraham@xxxxxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/tty/serial/samsung_tty.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index c9a870a8d155..f437f7363fd3 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1501,11 +1501,14 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,

if (!IS_ERR(ourport->baudclk)) {
clk_disable_unprepare(ourport->baudclk);
+ clk_put(ourport->baudclk);
ourport->baudclk = ERR_PTR(-EINVAL);
}

ourport->baudclk = clk;
ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
+ } else {
+ clk_put(clk);
}

if (ourport->info->has_divslot) {

--
2.56.0