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
6 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
8 commit 832e231cff476102e8204a9e7bddfe5c6154a375 upstream.
10 When the best clk is searched, we iterate over all possible clk.
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.
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>
25 drivers/tty/serial/samsung.c | 8 ++++++++
26 1 file changed, 8 insertions(+)
28 --- a/drivers/tty/serial/samsung.c
29 +++ b/drivers/tty/serial/samsung.c
30 @@ -1230,10 +1230,18 @@ static unsigned int s3c24xx_serial_getcl
31 calc_deviation = -calc_deviation;
33 if (calc_deviation < deviation) {
35 + * If we find a better clk, release the previous one, if
38 + if (!IS_ERR(*best_clk))
43 deviation = calc_deviation;