All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error
@ 2023-06-10 15:59 Christophe JAILLET
  2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Christophe JAILLET @ 2023-06-10 15:59 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Alim Akhtar, Greg Kroah-Hartman, Jiri Slaby,
	Thomas Abraham, Kukjin Kim
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, stable,
	Andi Shyti, linux-arm-kernel, linux-samsung-soc, linux-serial

If clk_get_rate() fails, the clk that has just been allocated needs to be
freed.

Cc: <stable@vger.kernel.org> # v3.3+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: Add an error message    [Andi Shyti]
    Add Cc: stable          [Andi Shyti]
    Add R-b tags

v1: https://lore.kernel.org/all/e4359d5ef206f5b349c1d15a515a1205e78dda55.1686285892.git.christophe.jaillet@wanadoo.fr/

Slightly unsure if Krzysztof's R-b should be kept or not.
v2 is not the same as v1, but the change looks small.
Sorry if I did wrong.
---
 drivers/tty/serial/samsung_tty.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index 2a7520ad3abd..a92a23e1964e 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1459,8 +1459,12 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 			continue;
 
 		rate = clk_get_rate(clk);
-		if (!rate)
+		if (!rate) {
+			dev_err(ourport->port.dev,
+				"Failed to get clock rate for %s.\n", clkname);
+			clk_put(clk);
 			continue;
+		}
 
 		if (ourport->info->has_divslot) {
 			unsigned long div = rate / req_baud;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk
  2023-06-10 15:59 [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Christophe JAILLET
@ 2023-06-10 15:59 ` Christophe JAILLET
  2023-06-12  5:27   ` Jiri Slaby
                     ` (2 more replies)
  2023-06-10 15:59 ` [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code Christophe JAILLET
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 12+ messages in thread
From: Christophe JAILLET @ 2023-06-10 15:59 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Alim Akhtar, Greg Kroah-Hartman, Jiri Slaby,
	Kukjin Kim, Thomas Abraham
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, stable,
	Andi Shyti, linux-arm-kernel, linux-samsung-soc, linux-serial

When the best clk is searched, we iterate over all possible clk.

If we find a better match, the previous one, if any, needs to be freed.
If a better match has already been found, we still need to free the new
one, otherwise it leaks.

Cc: <stable@vger.kernel.org> # v3.3+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
I think that some clk_put() are also missing somewhere else in the driver
but won't be able to investigate further.

v2: No code change
    Add Cc: stable          [Andi Shyti, as suggested for patch 1/2]
    Add R-b tags

v1: https://lore.kernel.org/all/93bf8f574310256fcea50e5c5a62b5c37e20bb14.1686285892.git.christophe.jaillet@wanadoo.fr/
---
 drivers/tty/serial/samsung_tty.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index a92a23e1964e..0b37019820b4 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1490,10 +1490,18 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 			calc_deviation = -calc_deviation;
 
 		if (calc_deviation < deviation) {
+			/*
+			 * If we find a better clk, release the previous one, if
+			 * any.
+			 */
+			if (!IS_ERR(*best_clk))
+				clk_put(*best_clk);
 			*best_clk = clk;
 			best_quot = quot;
 			*clk_num = cnt;
 			deviation = calc_deviation;
+		} else {
+			clk_put(clk);
 		}
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code
  2023-06-10 15:59 [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Christophe JAILLET
  2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
@ 2023-06-10 15:59 ` Christophe JAILLET
  2023-06-10 16:12   ` Andi Shyti
  2023-06-12  5:13   ` Jiri Slaby
  2023-06-12  5:27 ` [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Jiri Slaby
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Christophe JAILLET @ 2023-06-10 15:59 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Alim Akhtar, Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, Walter Harms,
	linux-arm-kernel, linux-samsung-soc, linux-serial

Use abs() instead of hand-writing it.

Suggested-by: Walter Harms <wharms@bfs.de>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: new patch
---
 drivers/tty/serial/samsung_tty.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index 0b37019820b4..b29e9dfd81a6 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -24,6 +24,7 @@
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
+#include <linux/math.h>
 #include <linux/module.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
@@ -1485,9 +1486,7 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 		}
 		quot--;
 
-		calc_deviation = req_baud - baud;
-		if (calc_deviation < 0)
-			calc_deviation = -calc_deviation;
+		calc_deviation = abs(req_baud - baud);
 
 		if (calc_deviation < deviation) {
 			/*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code
  2023-06-10 15:59 ` [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code Christophe JAILLET
@ 2023-06-10 16:12   ` Andi Shyti
  2023-06-12  5:13   ` Jiri Slaby
  1 sibling, 0 replies; 12+ messages in thread
From: Andi Shyti @ 2023-06-10 16:12 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Krzysztof Kozlowski, Alim Akhtar, Greg Kroah-Hartman, Jiri Slaby,
	linux-kernel, kernel-janitors, Walter Harms, linux-arm-kernel,
	linux-samsung-soc, linux-serial

Hi Christophe,

On Sat, Jun 10, 2023 at 05:59:27PM +0200, Christophe JAILLET wrote:
> Use abs() instead of hand-writing it.
> 
> Suggested-by: Walter Harms <wharms@bfs.de>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Andi Shyti <andi.shyti@kernel.org> 

Andi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code
  2023-06-10 15:59 ` [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code Christophe JAILLET
  2023-06-10 16:12   ` Andi Shyti
@ 2023-06-12  5:13   ` Jiri Slaby
  2023-06-12  5:31     ` Jiri Slaby
  1 sibling, 1 reply; 12+ messages in thread
From: Jiri Slaby @ 2023-06-12  5:13 UTC (permalink / raw)
  To: Christophe JAILLET, Krzysztof Kozlowski, Alim Akhtar,
	Greg Kroah-Hartman
  Cc: linux-kernel, kernel-janitors, Walter Harms, linux-arm-kernel,
	linux-samsung-soc, linux-serial

On 10. 06. 23, 17:59, Christophe JAILLET wrote:
> Use abs() instead of hand-writing it.
> 
> Suggested-by: Walter Harms <wharms@bfs.de>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> v2: new patch
> ---
>   drivers/tty/serial/samsung_tty.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
> index 0b37019820b4..b29e9dfd81a6 100644
> --- a/drivers/tty/serial/samsung_tty.c
> +++ b/drivers/tty/serial/samsung_tty.c
> @@ -24,6 +24,7 @@
>   #include <linux/dmaengine.h>
>   #include <linux/dma-mapping.h>
>   #include <linux/slab.h>
> +#include <linux/math.h>
>   #include <linux/module.h>
>   #include <linux/ioport.h>
>   #include <linux/io.h>
> @@ -1485,9 +1486,7 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
>   		}
>   		quot--;
>   
> -		calc_deviation = req_baud - baud;
> -		if (calc_deviation < 0)
> -			calc_deviation = -calc_deviation;
> +		calc_deviation = abs(req_baud - baud);

Does this work provided req_baud and baud are unsigned?

thanks,
-- 
js
suse labs


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk
  2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
@ 2023-06-12  5:27   ` Jiri Slaby
  2023-06-13 10:33   ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing gregkh
  2023-06-14  7:31   ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next gregkh
  2 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2023-06-12  5:27 UTC (permalink / raw)
  To: Christophe JAILLET, Krzysztof Kozlowski, Alim Akhtar,
	Greg Kroah-Hartman, Kukjin Kim, Thomas Abraham
  Cc: linux-kernel, kernel-janitors, stable, Andi Shyti,
	linux-arm-kernel, linux-samsung-soc, linux-serial

On 10. 06. 23, 17:59, Christophe JAILLET wrote:
> When the best clk is searched, we iterate over all possible clk.
> 
> If we find a better match, the previous one, if any, needs to be freed.
> If a better match has already been found, we still need to free the new
> one, otherwise it leaks.
> 
> Cc: <stable@vger.kernel.org> # v3.3+
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
> Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

thanks,
-- 
js
suse labs


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error
  2023-06-10 15:59 [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Christophe JAILLET
  2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
  2023-06-10 15:59 ` [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code Christophe JAILLET
@ 2023-06-12  5:27 ` Jiri Slaby
  2023-06-13 10:33 ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing gregkh
  2023-06-14  7:31 ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next gregkh
  4 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2023-06-12  5:27 UTC (permalink / raw)
  To: Christophe JAILLET, Krzysztof Kozlowski, Alim Akhtar,
	Greg Kroah-Hartman, Thomas Abraham, Kukjin Kim
  Cc: linux-kernel, kernel-janitors, stable, Andi Shyti,
	linux-arm-kernel, linux-samsung-soc, linux-serial

On 10. 06. 23, 17:59, Christophe JAILLET wrote:
> If clk_get_rate() fails, the clk that has just been allocated needs to be
> freed.
> 
> Cc: <stable@vger.kernel.org> # v3.3+
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
> Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

thanks,
-- 
js
suse labs


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code
  2023-06-12  5:13   ` Jiri Slaby
@ 2023-06-12  5:31     ` Jiri Slaby
  0 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2023-06-12  5:31 UTC (permalink / raw)
  To: Christophe JAILLET, Krzysztof Kozlowski, Alim Akhtar,
	Greg Kroah-Hartman
  Cc: linux-kernel, kernel-janitors, Walter Harms, linux-arm-kernel,
	linux-samsung-soc, linux-serial

On 12. 06. 23, 7:13, Jiri Slaby wrote:
> On 10. 06. 23, 17:59, Christophe JAILLET wrote:
>> Use abs() instead of hand-writing it.
>>
>> Suggested-by: Walter Harms <wharms@bfs.de>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> v2: new patch
>> ---
>>   drivers/tty/serial/samsung_tty.c | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/tty/serial/samsung_tty.c 
>> b/drivers/tty/serial/samsung_tty.c
>> index 0b37019820b4..b29e9dfd81a6 100644
>> --- a/drivers/tty/serial/samsung_tty.c
>> +++ b/drivers/tty/serial/samsung_tty.c
>> @@ -24,6 +24,7 @@
>>   #include <linux/dmaengine.h>
>>   #include <linux/dma-mapping.h>
>>   #include <linux/slab.h>
>> +#include <linux/math.h>
>>   #include <linux/module.h>
>>   #include <linux/ioport.h>
>>   #include <linux/io.h>
>> @@ -1485,9 +1486,7 @@ static unsigned int s3c24xx_serial_getclk(struct 
>> s3c24xx_uart_port *ourport,
>>           }
>>           quot--;
>> -        calc_deviation = req_baud - baud;
>> -        if (calc_deviation < 0)
>> -            calc_deviation = -calc_deviation;
>> +        calc_deviation = abs(req_baud - baud);
> 
> Does this work provided req_baud and baud are unsigned?

Oh, yes, it does, _hopefully_. A bit unexpectedly for me, but:
  * abs - return absolute value of an argument
  * @x: the value.  If it is unsigned type, it is converted to signed 
type first.

So:

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

It would help noting this in the commit log.

> thanks,-- 
js
suse labs


^ permalink raw reply	[flat|nested] 12+ messages in thread

* patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing
  2023-06-10 15:59 [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Christophe JAILLET
                   ` (2 preceding siblings ...)
  2023-06-12  5:27 ` [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Jiri Slaby
@ 2023-06-13 10:33 ` gregkh
  2023-06-14  7:31 ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next gregkh
  4 siblings, 0 replies; 12+ messages in thread
From: gregkh @ 2023-06-13 10:33 UTC (permalink / raw)
  To: christophe.jaillet, andi.shyti, gregkh, jirislaby,
	krzysztof.kozlowski, stable


This is a note to let you know that I've just added the patch titled

    tty: serial: samsung_tty: Fix a memory leak in

to my tty git tree which can be found at
    git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-testing branch.

The patch will show up in the next release of the linux-next tree
(usually sometime within the next 24 hours during the week.)

The patch will be merged to the tty-next branch sometime soon,
after it passes testing, and the merge window is open.

If you have any questions about this process, please let me know.


From a9c09546e903f1068acfa38e1ee18bded7114b37 Mon Sep 17 00:00:00 2001
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 10 Jun 2023 17:59:25 +0200
Subject: tty: serial: samsung_tty: Fix a memory leak in
 s3c24xx_serial_getclk() in case of error

If clk_get_rate() fails, the clk that has just been allocated needs to be
freed.

Cc: <stable@vger.kernel.org> # v3.3+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Message-ID: <e4baf6039368f52e5a5453982ddcb9a330fc689e.1686412569.git.christophe.jaillet@wanadoo.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/tty/serial/samsung_tty.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index 2a7520ad3abd..a92a23e1964e 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1459,8 +1459,12 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 			continue;
 
 		rate = clk_get_rate(clk);
-		if (!rate)
+		if (!rate) {
+			dev_err(ourport->port.dev,
+				"Failed to get clock rate for %s.\n", clkname);
+			clk_put(clk);
 			continue;
+		}
 
 		if (ourport->info->has_divslot) {
 			unsigned long div = rate / req_baud;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing
  2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
  2023-06-12  5:27   ` Jiri Slaby
@ 2023-06-13 10:33   ` gregkh
  2023-06-14  7:31   ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next gregkh
  2 siblings, 0 replies; 12+ messages in thread
From: gregkh @ 2023-06-13 10:33 UTC (permalink / raw)
  To: christophe.jaillet, andi.shyti, gregkh, jirislaby,
	krzysztof.kozlowski, stable


This is a note to let you know that I've just added the patch titled

    tty: serial: samsung_tty: Fix a memory leak in

to my tty git tree which can be found at
    git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-testing branch.

The patch will show up in the next release of the linux-next tree
(usually sometime within the next 24 hours during the week.)

The patch will be merged to the tty-next branch sometime soon,
after it passes testing, and the merge window is open.

If you have any questions about this process, please let me know.


From 832e231cff476102e8204a9e7bddfe5c6154a375 Mon Sep 17 00:00:00 2001
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 10 Jun 2023 17:59:26 +0200
Subject: tty: serial: samsung_tty: Fix a memory leak in
 s3c24xx_serial_getclk() when iterating clk

When the best clk is searched, we iterate over all possible clk.

If we find a better match, the previous one, if any, needs to be freed.
If a better match has already been found, we still need to free the new
one, otherwise it leaks.

Cc: <stable@vger.kernel.org> # v3.3+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Message-ID: <cf3e0053d2fc7391b2d906a86cd01a5ef15fb9dc.1686412569.git.christophe.jaillet@wanadoo.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/tty/serial/samsung_tty.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index a92a23e1964e..0b37019820b4 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1490,10 +1490,18 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 			calc_deviation = -calc_deviation;
 
 		if (calc_deviation < deviation) {
+			/*
+			 * If we find a better clk, release the previous one, if
+			 * any.
+			 */
+			if (!IS_ERR(*best_clk))
+				clk_put(*best_clk);
 			*best_clk = clk;
 			best_quot = quot;
 			*clk_num = cnt;
 			deviation = calc_deviation;
+		} else {
+			clk_put(clk);
 		}
 	}
 
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next
  2023-06-10 15:59 [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Christophe JAILLET
                   ` (3 preceding siblings ...)
  2023-06-13 10:33 ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing gregkh
@ 2023-06-14  7:31 ` gregkh
  4 siblings, 0 replies; 12+ messages in thread
From: gregkh @ 2023-06-14  7:31 UTC (permalink / raw)
  To: christophe.jaillet, andi.shyti, gregkh, jirislaby,
	krzysztof.kozlowski, stable


This is a note to let you know that I've just added the patch titled

    tty: serial: samsung_tty: Fix a memory leak in

to my tty git tree which can be found at
    git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-next branch.

The patch will show up in the next release of the linux-next tree
(usually sometime within the next 24 hours during the week.)

The patch will also be merged in the next major kernel release
during the merge window.

If you have any questions about this process, please let me know.


From a9c09546e903f1068acfa38e1ee18bded7114b37 Mon Sep 17 00:00:00 2001
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 10 Jun 2023 17:59:25 +0200
Subject: tty: serial: samsung_tty: Fix a memory leak in
 s3c24xx_serial_getclk() in case of error

If clk_get_rate() fails, the clk that has just been allocated needs to be
freed.

Cc: <stable@vger.kernel.org> # v3.3+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Message-ID: <e4baf6039368f52e5a5453982ddcb9a330fc689e.1686412569.git.christophe.jaillet@wanadoo.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/tty/serial/samsung_tty.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index 2a7520ad3abd..a92a23e1964e 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1459,8 +1459,12 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 			continue;
 
 		rate = clk_get_rate(clk);
-		if (!rate)
+		if (!rate) {
+			dev_err(ourport->port.dev,
+				"Failed to get clock rate for %s.\n", clkname);
+			clk_put(clk);
 			continue;
+		}
 
 		if (ourport->info->has_divslot) {
 			unsigned long div = rate / req_baud;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next
  2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
  2023-06-12  5:27   ` Jiri Slaby
  2023-06-13 10:33   ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing gregkh
@ 2023-06-14  7:31   ` gregkh
  2 siblings, 0 replies; 12+ messages in thread
From: gregkh @ 2023-06-14  7:31 UTC (permalink / raw)
  To: christophe.jaillet, andi.shyti, gregkh, jirislaby,
	krzysztof.kozlowski, stable


This is a note to let you know that I've just added the patch titled

    tty: serial: samsung_tty: Fix a memory leak in

to my tty git tree which can be found at
    git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-next branch.

The patch will show up in the next release of the linux-next tree
(usually sometime within the next 24 hours during the week.)

The patch will also be merged in the next major kernel release
during the merge window.

If you have any questions about this process, please let me know.


From 832e231cff476102e8204a9e7bddfe5c6154a375 Mon Sep 17 00:00:00 2001
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 10 Jun 2023 17:59:26 +0200
Subject: tty: serial: samsung_tty: Fix a memory leak in
 s3c24xx_serial_getclk() when iterating clk

When the best clk is searched, we iterate over all possible clk.

If we find a better match, the previous one, if any, needs to be freed.
If a better match has already been found, we still need to free the new
one, otherwise it leaks.

Cc: <stable@vger.kernel.org> # v3.3+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Message-ID: <cf3e0053d2fc7391b2d906a86cd01a5ef15fb9dc.1686412569.git.christophe.jaillet@wanadoo.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/tty/serial/samsung_tty.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index a92a23e1964e..0b37019820b4 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1490,10 +1490,18 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
 			calc_deviation = -calc_deviation;
 
 		if (calc_deviation < deviation) {
+			/*
+			 * If we find a better clk, release the previous one, if
+			 * any.
+			 */
+			if (!IS_ERR(*best_clk))
+				clk_put(*best_clk);
 			*best_clk = clk;
 			best_quot = quot;
 			*clk_num = cnt;
 			deviation = calc_deviation;
+		} else {
+			clk_put(clk);
 		}
 	}
 
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-06-14  7:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-10 15:59 [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Christophe JAILLET
2023-06-10 15:59 ` [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Christophe JAILLET
2023-06-12  5:27   ` Jiri Slaby
2023-06-13 10:33   ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing gregkh
2023-06-14  7:31   ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next gregkh
2023-06-10 15:59 ` [PATCH v2 3/3] tty: serial: samsung_tty: Use abs() to simplify some code Christophe JAILLET
2023-06-10 16:12   ` Andi Shyti
2023-06-12  5:13   ` Jiri Slaby
2023-06-12  5:31     ` Jiri Slaby
2023-06-12  5:27 ` [PATCH v2 1/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error Jiri Slaby
2023-06-13 10:33 ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-testing gregkh
2023-06-14  7:31 ` patch "tty: serial: samsung_tty: Fix a memory leak in" added to tty-next gregkh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.