]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
32d0a0eb5b91657e210657258cd0109d0cc1d315
[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 ---
25 drivers/tty/serial/samsung_tty.c | 8 ++++++++
26 1 file changed, 8 insertions(+)
27
28 --- a/drivers/tty/serial/samsung_tty.c
29 +++ b/drivers/tty/serial/samsung_tty.c
30 @@ -1498,10 +1498,18 @@ static unsigned int s3c24xx_serial_getcl
31 calc_deviation = -calc_deviation;
32
33 if (calc_deviation < deviation) {
34 + /*
35 + * If we find a better clk, release the previous one, if
36 + * any.
37 + */
38 + if (!IS_ERR(*best_clk))
39 + clk_put(*best_clk);
40 *best_clk = clk;
41 best_quot = quot;
42 *clk_num = cnt;
43 deviation = calc_deviation;
44 + } else {
45 + clk_put(clk);
46 }
47 }
48