Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH] clk: samsung: exynos5410: fix refcount leak
@ 2026-05-26  6:13 Alexander A. Klimov
  2026-05-26  6:13 ` [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak Alexander A. Klimov
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Alexander A. Klimov @ 2026-05-26  6:13 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Sylwester Nawrocki, Chanwoo Choi,
	Alim Akhtar, Michael Turquette, Stephen Boyd, Brian Masney,
	open list:SAMSUNG SOC CLOCK DRIVERS,
	open list:COMMON CLK FRAMEWORK,
	moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
	open list
  Cc: Alexander A. Klimov

Every value returned from of_clk_get() is supposed to be cleaned up
via clk_put() once not needed anymore.

Fixes: be95d2c7d918 ("clk: samsung: Add support for EPLL on exynos5410")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
 drivers/clk/samsung/clk-exynos5410.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/samsung/clk-exynos5410.c b/drivers/clk/samsung/clk-exynos5410.c
index baa9988c7bb7..0cd9b0392cf5 100644
--- a/drivers/clk/samsung/clk-exynos5410.c
+++ b/drivers/clk/samsung/clk-exynos5410.c
@@ -269,8 +269,12 @@ static void __init exynos5410_clk_init(struct device_node *np)
 {
 	struct clk *xxti = of_clk_get(np, 0);
 
-	if (!IS_ERR(xxti) && clk_get_rate(xxti) == 24 * MHZ)
-		exynos5410_plls[epll].rate_table = exynos5410_pll2550x_24mhz_tbl;
+	if (!IS_ERR(xxti)) {
+		if (clk_get_rate(xxti) == 24 * MHZ)
+			exynos5410_plls[epll].rate_table =
+				exynos5410_pll2550x_24mhz_tbl;
+		clk_put(xxti);
+	}
 
 	samsung_cmu_register_one(np, &cmu);
 
-- 
2.54.0


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

* [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak
  2026-05-26  6:13 [PATCH] clk: samsung: exynos5410: fix refcount leak Alexander A. Klimov
@ 2026-05-26  6:13 ` Alexander A. Klimov
  2026-05-26 17:33   ` Brian Masney
  2026-05-28 20:30   ` Thierry Reding
  2026-05-26 17:29 ` [PATCH] clk: samsung: exynos5410: fix refcount leak Brian Masney
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Alexander A. Klimov @ 2026-05-26  6:13 UTC (permalink / raw)
  To: Peter De Schrijver, Prashant Gaikwad, Michael Turquette,
	Stephen Boyd, Brian Masney, Thierry Reding, Jonathan Hunter,
	Dmitry Osipenko, open list:COMMON CLK FRAMEWORK,
	open list:TEGRA ARCHITECTURE SUPPORT, open list
  Cc: Alexander A. Klimov

Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:

    MEM = krealloc(MEM, SZ, GFP);

If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:

    TMP = krealloc(MEM, SZ, GFP);
    if (!TMP) return;
    MEM = TMP;

Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
 drivers/clk/tegra/clk-tegra124-emc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
index f3b2c96fdcfc..8053fbbb06c8 100644
--- a/drivers/clk/tegra/clk-tegra124-emc.c
+++ b/drivers/clk/tegra/clk-tegra124-emc.c
@@ -446,14 +446,13 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
 	struct emc_timing *timings_ptr;
 	int child_count = of_get_child_count(node);
 	int i = 0, err;
-	size_t size;
+	size_t size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);
+	void *mem = krealloc(tegra->timings, size, GFP_KERNEL);
 
-	size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);
-
-	tegra->timings = krealloc(tegra->timings, size, GFP_KERNEL);
-	if (!tegra->timings)
+	if (!mem)
 		return -ENOMEM;
 
+	tegra->timings = mem;
 	timings_ptr = tegra->timings + tegra->num_timings;
 	tegra->num_timings += child_count;
 
-- 
2.54.0


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

* Re: [PATCH] clk: samsung: exynos5410: fix refcount leak
  2026-05-26  6:13 [PATCH] clk: samsung: exynos5410: fix refcount leak Alexander A. Klimov
  2026-05-26  6:13 ` [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak Alexander A. Klimov
@ 2026-05-26 17:29 ` Brian Masney
  2026-05-28  1:15 ` Alexey Klimov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Brian Masney @ 2026-05-26 17:29 UTC (permalink / raw)
  To: Alexander A. Klimov
  Cc: Krzysztof Kozlowski, Sylwester Nawrocki, Chanwoo Choi,
	Alim Akhtar, Michael Turquette, Stephen Boyd,
	open list:SAMSUNG SOC CLOCK DRIVERS,
	open list:COMMON CLK FRAMEWORK,
	moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
	open list

On Tue, May 26, 2026 at 08:13:12AM +0200, Alexander A. Klimov wrote:
> Every value returned from of_clk_get() is supposed to be cleaned up
> via clk_put() once not needed anymore.
> 
> Fixes: be95d2c7d918 ("clk: samsung: Add support for EPLL on exynos5410")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>

Reviewed-by: Brian Masney <bmasney@redhat.com>


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

* Re: [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak
  2026-05-26  6:13 ` [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak Alexander A. Klimov
@ 2026-05-26 17:33   ` Brian Masney
  2026-05-28 20:30   ` Thierry Reding
  1 sibling, 0 replies; 11+ messages in thread
From: Brian Masney @ 2026-05-26 17:33 UTC (permalink / raw)
  To: Alexander A. Klimov
  Cc: Peter De Schrijver, Prashant Gaikwad, Michael Turquette,
	Stephen Boyd, Thierry Reding, Jonathan Hunter, Dmitry Osipenko,
	open list:COMMON CLK FRAMEWORK,
	open list:TEGRA ARCHITECTURE SUPPORT, open list

On Tue, May 26, 2026 at 08:13:13AM +0200, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
> 
>     MEM = krealloc(MEM, SZ, GFP);
> 
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
> 
>     TMP = krealloc(MEM, SZ, GFP);
>     if (!TMP) return;
>     MEM = TMP;
> 
> Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>

Reviewed-by: Brian Masney <bmasney@redhat.com>


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

* Re: [PATCH] clk: samsung: exynos5410: fix refcount leak
  2026-05-26  6:13 [PATCH] clk: samsung: exynos5410: fix refcount leak Alexander A. Klimov
  2026-05-26  6:13 ` [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak Alexander A. Klimov
  2026-05-26 17:29 ` [PATCH] clk: samsung: exynos5410: fix refcount leak Brian Masney
@ 2026-05-28  1:15 ` Alexey Klimov
  2026-05-28  8:02 ` Peter Griffin
  2026-05-30 16:26 ` Krzysztof Kozlowski
  4 siblings, 0 replies; 11+ messages in thread
From: Alexey Klimov @ 2026-05-28  1:15 UTC (permalink / raw)
  To: Alexander A. Klimov, Krzysztof Kozlowski, Sylwester Nawrocki,
	Chanwoo Choi, Alim Akhtar, Michael Turquette, Stephen Boyd,
	Brian Masney, open list:SAMSUNG SOC CLOCK DRIVERS,
	open list:COMMON CLK FRAMEWORK,
	moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
	open list

On Tue May 26, 2026 at 7:13 AM BST, Alexander A. Klimov wrote:
> Every value returned from of_clk_get() is supposed to be cleaned up
> via clk_put() once not needed anymore.
>
> Fixes: be95d2c7d918 ("clk: samsung: Add support for EPLL on exynos5410")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>

Reviewed-by: Alexey Klimov <alexey.klimov@linaro.org>

> ---
>  drivers/clk/samsung/clk-exynos5410.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/samsung/clk-exynos5410.c b/drivers/clk/samsung/clk-exynos5410.c
> index baa9988c7bb7..0cd9b0392cf5 100644
> --- a/drivers/clk/samsung/clk-exynos5410.c
> +++ b/drivers/clk/samsung/clk-exynos5410.c
> @@ -269,8 +269,12 @@ static void __init exynos5410_clk_init(struct device_node *np)
>  {
>  	struct clk *xxti = of_clk_get(np, 0);
>  
> -	if (!IS_ERR(xxti) && clk_get_rate(xxti) == 24 * MHZ)
> -		exynos5410_plls[epll].rate_table = exynos5410_pll2550x_24mhz_tbl;
> +	if (!IS_ERR(xxti)) {
> +		if (clk_get_rate(xxti) == 24 * MHZ)
> +			exynos5410_plls[epll].rate_table =
> +				exynos5410_pll2550x_24mhz_tbl;
> +		clk_put(xxti);
> +	}
>  
>  	samsung_cmu_register_one(np, &cmu);

Best regards,
Alexey Klimov


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

* Re: [PATCH] clk: samsung: exynos5410: fix refcount leak
  2026-05-26  6:13 [PATCH] clk: samsung: exynos5410: fix refcount leak Alexander A. Klimov
                   ` (2 preceding siblings ...)
  2026-05-28  1:15 ` Alexey Klimov
@ 2026-05-28  8:02 ` Peter Griffin
  2026-05-30 16:26 ` Krzysztof Kozlowski
  4 siblings, 0 replies; 11+ messages in thread
From: Peter Griffin @ 2026-05-28  8:02 UTC (permalink / raw)
  To: Alexander A. Klimov
  Cc: Krzysztof Kozlowski, Sylwester Nawrocki, Chanwoo Choi,
	Alim Akhtar, Michael Turquette, Stephen Boyd, Brian Masney,
	open list:SAMSUNG SOC CLOCK DRIVERS,
	open list:COMMON CLK FRAMEWORK,
	moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
	open list

On Tue, 26 May 2026 at 07:13, Alexander A. Klimov
<grandmaster@al2klimov.de> wrote:
>
> Every value returned from of_clk_get() is supposed to be cleaned up
> via clk_put() once not needed anymore.
>
> Fixes: be95d2c7d918 ("clk: samsung: Add support for EPLL on exynos5410")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---

Reviewed-by: Peter Griffin <peter.griffin@linaro.org>

>  drivers/clk/samsung/clk-exynos5410.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/samsung/clk-exynos5410.c b/drivers/clk/samsung/clk-exynos5410.c
> index baa9988c7bb7..0cd9b0392cf5 100644
> --- a/drivers/clk/samsung/clk-exynos5410.c
> +++ b/drivers/clk/samsung/clk-exynos5410.c
> @@ -269,8 +269,12 @@ static void __init exynos5410_clk_init(struct device_node *np)
>  {
>         struct clk *xxti = of_clk_get(np, 0);
>
> -       if (!IS_ERR(xxti) && clk_get_rate(xxti) == 24 * MHZ)
> -               exynos5410_plls[epll].rate_table = exynos5410_pll2550x_24mhz_tbl;
> +       if (!IS_ERR(xxti)) {
> +               if (clk_get_rate(xxti) == 24 * MHZ)
> +                       exynos5410_plls[epll].rate_table =
> +                               exynos5410_pll2550x_24mhz_tbl;
> +               clk_put(xxti);
> +       }
>
>         samsung_cmu_register_one(np, &cmu);
>
> --
> 2.54.0
>
>

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

* Re: [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak
  2026-05-26  6:13 ` [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak Alexander A. Klimov
  2026-05-26 17:33   ` Brian Masney
@ 2026-05-28 20:30   ` Thierry Reding
  2026-05-31 19:52     ` [PATCH v2] " Alexander A. Klimov
  1 sibling, 1 reply; 11+ messages in thread
From: Thierry Reding @ 2026-05-28 20:30 UTC (permalink / raw)
  To: Alexander A. Klimov
  Cc: Peter De Schrijver, Prashant Gaikwad, Michael Turquette,
	Stephen Boyd, Brian Masney, Jonathan Hunter, Dmitry Osipenko,
	open list:COMMON CLK FRAMEWORK,
	open list:TEGRA ARCHITECTURE SUPPORT, open list

[-- Attachment #1: Type: text/plain, Size: 1698 bytes --]

On Tue, May 26, 2026 at 08:13:13AM +0200, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
> 
>     MEM = krealloc(MEM, SZ, GFP);
> 
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
> 
>     TMP = krealloc(MEM, SZ, GFP);
>     if (!TMP) return;
>     MEM = TMP;
> 
> Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
>  drivers/clk/tegra/clk-tegra124-emc.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
> index f3b2c96fdcfc..8053fbbb06c8 100644
> --- a/drivers/clk/tegra/clk-tegra124-emc.c
> +++ b/drivers/clk/tegra/clk-tegra124-emc.c
> @@ -446,14 +446,13 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
>  	struct emc_timing *timings_ptr;
>  	int child_count = of_get_child_count(node);
>  	int i = 0, err;
> -	size_t size;
> +	size_t size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);
> +	void *mem = krealloc(tegra->timings, size, GFP_KERNEL);
>  
> -	size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);

This looks really wild now. I think it'd be better to follow the
original style:

	size_t size;
	void *mem;

	size = ...;

	mem = krealloc(...);
	if (!mem)
		...

With that:

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] clk: samsung: exynos5410: fix refcount leak
  2026-05-26  6:13 [PATCH] clk: samsung: exynos5410: fix refcount leak Alexander A. Klimov
                   ` (3 preceding siblings ...)
  2026-05-28  8:02 ` Peter Griffin
@ 2026-05-30 16:26 ` Krzysztof Kozlowski
  2026-05-31  9:27   ` Alexander A. Klimov
  4 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-05-30 16:26 UTC (permalink / raw)
  To: Alexander A. Klimov, Sylwester Nawrocki, Chanwoo Choi,
	Alim Akhtar, Michael Turquette, Stephen Boyd, Brian Masney,
	open list:SAMSUNG SOC CLOCK DRIVERS,
	open list:COMMON CLK FRAMEWORK,
	moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
	open list

On 26/05/2026 08:13, Alexander A. Klimov wrote:
> Every value returned from of_clk_get() is supposed to be cleaned up
> via clk_put() once not needed anymore.
> 
> Fixes: be95d2c7d918 ("clk: samsung: Add support for EPLL on exynos5410")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>


Does not apply - you messed somehow sending these.

Grabbing thread from
lore.kernel.org/all/20260526061321.6123-1-grandmaster@al2klimov.de/t.mbox.gz
Checking for newer revisions
Grabbing search results from lore.kernel.org
Analyzing 13 messages in the thread
WARNING: duplicate messages found at index 1
   Subject 1: dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1
   Subject 2: tlclk: if sscanf() fails, fall back to 0, not random value
  2 is not a reply... assume additional patch
WARNING: duplicate messages found at index 1
   Subject 1: clk: samsung: exynos5410: fix refcount leak
   Subject 2: dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1
  2 is not a reply... assume additional patch
Assuming new revision: v2 ([PATCH] clk: tegra: tegra124-emc: fix
krealloc() memory leak)


Best regards,
Krzysztof

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

* Re: [PATCH] clk: samsung: exynos5410: fix refcount leak
  2026-05-30 16:26 ` Krzysztof Kozlowski
@ 2026-05-31  9:27   ` Alexander A. Klimov
  0 siblings, 0 replies; 11+ messages in thread
From: Alexander A. Klimov @ 2026-05-31  9:27 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Sylwester Nawrocki, Chanwoo Choi,
	Alim Akhtar, Michael Turquette, Stephen Boyd, Brian Masney,
	open list:SAMSUNG SOC CLOCK DRIVERS,
	open list:COMMON CLK FRAMEWORK,
	moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
	open list



On 5/30/26 18:26, Krzysztof Kozlowski wrote:
> On 26/05/2026 08:13, Alexander A. Klimov wrote:
>> Every value returned from of_clk_get() is supposed to be cleaned up
>> via clk_put() once not needed anymore.
>>
>> Fixes: be95d2c7d918 ("clk: samsung: Add support for EPLL on exynos5410")
>> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> 
> 
> Does not apply - you messed somehow sending these.

Strange... copy&paste from
https://lore.kernel.org/all/20260526061321.6123-1-grandmaster@al2klimov.de/
(From: ... 2.54.0) applies to Linus' master.

Wait... ! Don't say because I fired all my compiled patches
at once via git-send-email(1), they assembled to one thread?
🙈

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

* [PATCH v2] clk: tegra: tegra124-emc: fix krealloc() memory leak
  2026-05-28 20:30   ` Thierry Reding
@ 2026-05-31 19:52     ` Alexander A. Klimov
  2026-07-30 15:55       ` Thierry Reding
  0 siblings, 1 reply; 11+ messages in thread
From: Alexander A. Klimov @ 2026-05-31 19:52 UTC (permalink / raw)
  Cc: Alexander A. Klimov, Peter De Schrijver, Prashant Gaikwad,
	Michael Turquette, Stephen Boyd, Brian Masney, Thierry Reding,
	Jonathan Hunter, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Dmitry Osipenko,
	open list:COMMON CLK FRAMEWORK,
	open list:TEGRA ARCHITECTURE SUPPORT, open list,
	open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b

Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:

    MEM = krealloc(MEM, SZ, GFP);

If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:

    TMP = krealloc(MEM, SZ, GFP);
    if (!TMP) return;
    MEM = TMP;

Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
 v2: Separate variable declaration/init
 v2: While on it, enhance variable name
 v2: While on it, explicit variable type
 v2: While on it, re-order variables (reverse Xmas tree)

 [✓] scripts/checkpatch.pl --strict
 [✓] allmodconfig compiled (i686, LLVM)
 [✓] localyesconfig booted (IBM T43)

 Note to myself: use --in-reply-to=ahilgKKwkttOd9H6@orome

 drivers/clk/tegra/clk-tegra124-emc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
index f3b2c96fdcfc..81e4c02a807c 100644
--- a/drivers/clk/tegra/clk-tegra124-emc.c
+++ b/drivers/clk/tegra/clk-tegra124-emc.c
@@ -445,15 +445,17 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
 {
 	struct emc_timing *timings_ptr;
 	int child_count = of_get_child_count(node);
+	struct emc_timing *timings;
 	int i = 0, err;
 	size_t size;
 
 	size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);
 
-	tegra->timings = krealloc(tegra->timings, size, GFP_KERNEL);
-	if (!tegra->timings)
+	timings = krealloc(tegra->timings, size, GFP_KERNEL);
+	if (!timings)
 		return -ENOMEM;
 
+	tegra->timings = timings;
 	timings_ptr = tegra->timings + tegra->num_timings;
 	tegra->num_timings += child_count;
 
-- 
2.54.0


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

* Re: [PATCH v2] clk: tegra: tegra124-emc: fix krealloc() memory leak
  2026-05-31 19:52     ` [PATCH v2] " Alexander A. Klimov
@ 2026-07-30 15:55       ` Thierry Reding
  0 siblings, 0 replies; 11+ messages in thread
From: Thierry Reding @ 2026-07-30 15:55 UTC (permalink / raw)
  To: Alexander A. Klimov
  Cc: Peter De Schrijver, Prashant Gaikwad, Michael Turquette,
	Stephen Boyd, Brian Masney, Jonathan Hunter, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Dmitry Osipenko,
	open list:COMMON CLK FRAMEWORK,
	open list:TEGRA ARCHITECTURE SUPPORT, open list,
	open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b

[-- Attachment #1: Type: text/plain, Size: 2614 bytes --]

On Sun, May 31, 2026 at 09:52:52PM +0200, Alexander A. Klimov wrote:
> Don't just overwrite the original pointer passed to krealloc()
> with its return value without checking latter:
> 
>     MEM = krealloc(MEM, SZ, GFP);
> 
> If krealloc() returns NULL, that erases the pointer
> to the still allocated memory, hence leaks this memory.
> Instead, use a temporary variable, check it's not NULL
> and only then assign it to the original pointer:
> 
>     TMP = krealloc(MEM, SZ, GFP);
>     if (!TMP) return;
>     MEM = TMP;
> 
> Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
>  v2: Separate variable declaration/init
>  v2: While on it, enhance variable name
>  v2: While on it, explicit variable type
>  v2: While on it, re-order variables (reverse Xmas tree)
> 
>  [✓] scripts/checkpatch.pl --strict
>  [✓] allmodconfig compiled (i686, LLVM)
>  [✓] localyesconfig booted (IBM T43)

The latter two are a bit pointless because they are not going to hit
this because the driver depends on ARCH_TEGRA which doesn't exist on
i686 allmodconfig and booting this on a T43 isn't going to hit this
either.

>  Note to myself: use --in-reply-to=ahilgKKwkttOd9H6@orome

It's not generally useful to send as replies to earlier versions. Just
regular sending is good enough. We have tools to track versions and
such.

> 
>  drivers/clk/tegra/clk-tegra124-emc.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
> index f3b2c96fdcfc..81e4c02a807c 100644
> --- a/drivers/clk/tegra/clk-tegra124-emc.c
> +++ b/drivers/clk/tegra/clk-tegra124-emc.c
> @@ -445,15 +445,17 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
>  {
>  	struct emc_timing *timings_ptr;
>  	int child_count = of_get_child_count(node);
> +	struct emc_timing *timings;

I guess we could've reused timings_ptr. Or remove timings_ptr and use
the new one, but I guess this is fine, too:

Reviewed-by: Thierry Reding <treding@nvidia.com>

>  	int i = 0, err;
>  	size_t size;
>  
>  	size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);
>  
> -	tegra->timings = krealloc(tegra->timings, size, GFP_KERNEL);
> -	if (!tegra->timings)
> +	timings = krealloc(tegra->timings, size, GFP_KERNEL);
> +	if (!timings)
>  		return -ENOMEM;
>  
> +	tegra->timings = timings;
>  	timings_ptr = tegra->timings + tegra->num_timings;
>  	tegra->num_timings += child_count;

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2026-07-30 15:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26  6:13 [PATCH] clk: samsung: exynos5410: fix refcount leak Alexander A. Klimov
2026-05-26  6:13 ` [PATCH] clk: tegra: tegra124-emc: fix krealloc() memory leak Alexander A. Klimov
2026-05-26 17:33   ` Brian Masney
2026-05-28 20:30   ` Thierry Reding
2026-05-31 19:52     ` [PATCH v2] " Alexander A. Klimov
2026-07-30 15:55       ` Thierry Reding
2026-05-26 17:29 ` [PATCH] clk: samsung: exynos5410: fix refcount leak Brian Masney
2026-05-28  1:15 ` Alexey Klimov
2026-05-28  8:02 ` Peter Griffin
2026-05-30 16:26 ` Krzysztof Kozlowski
2026-05-31  9:27   ` Alexander A. Klimov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox