]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
08c6e43accb5b68a47eae6eba5efd62fbd45e496
[thirdparty/kernel/stable-queue.git] /
1 From 832e231cff476102e8204a9e7bddfe5c6154a375 Mon Sep 17 00:00:00 2001
2 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
3 Date: Sat, 10 Jun 2023 17:59:26 +0200
4 Subject: tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk
5
6 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
7
8 commit 832e231cff476102e8204a9e7bddfe5c6154a375 upstream.
9
10 When the best clk is searched, we iterate over all possible clk.
11
12 If we find a better match, the previous one, if any, needs to be freed.
13 If a better match has already been found, we still need to free the new
14 one, otherwise it leaks.
15
16 Cc: <stable@vger.kernel.org> # v3.3+
17 Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
18 Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
19 Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
20 Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
21 Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
22 Message-ID: <cf3e0053d2fc7391b2d906a86cd01a5ef15fb9dc.1686412569.git.christophe.jaillet@wanadoo.fr>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 ---
26 drivers/tty/serial/samsung_tty.c | 8 ++++++++
27 1 file changed, 8 insertions(+)
28
29 diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
30 index a92a23e1964e..0b37019820b4 100644
31 --- a/drivers/tty/serial/samsung_tty.c
32 +++ b/drivers/tty/serial/samsung_tty.c
33 @@ -1490,10 +1490,18 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
34 calc_deviation = -calc_deviation;
35
36 if (calc_deviation < deviation) {
37 + /*
38 + * If we find a better clk, release the previous one, if
39 + * any.
40 + */
41 + if (!IS_ERR(*best_clk))
42 + clk_put(*best_clk);
43 *best_clk = clk;
44 best_quot = quot;
45 *clk_num = cnt;
46 deviation = calc_deviation;
47 + } else {
48 + clk_put(clk);
49 }
50 }
51
52 --
53 2.41.0
54