Linux clock framework development
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@kernel.org>
To: "Alexander A. Klimov" <grandmaster@al2klimov.de>
Cc: Peter De Schrijver <pdeschrijver@nvidia.com>,
	 Prashant Gaikwad <pgaikwad@nvidia.com>,
	Michael Turquette <mturquette@baylibre.com>,
	 Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney@redhat.com>,
	 Jonathan Hunter <jonathanh@nvidia.com>,
	Nathan Chancellor <nathan@kernel.org>,
	 Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Bill Wendling <morbo@google.com>,
	 Justin Stitt <justinstitt@google.com>,
	Dmitry Osipenko <digetx@gmail.com>,
	 "open list:COMMON CLK FRAMEWORK" <linux-clk@vger.kernel.org>,
	 "open list:TEGRA ARCHITECTURE SUPPORT"
	<linux-tegra@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	 "open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b"
	<llvm@lists.linux.dev>
Subject: Re: [PATCH v2] clk: tegra: tegra124-emc: fix krealloc() memory leak
Date: Thu, 30 Jul 2026 17:55:01 +0200	[thread overview]
Message-ID: <amtyoOXfiPic0f5H@orome> (raw)
In-Reply-To: <20260531195313.99447-1-grandmaster@al2klimov.de>

[-- 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 --]

  reply	other threads:[~2026-07-30 15:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=amtyoOXfiPic0f5H@orome \
    --to=thierry.reding@kernel.org \
    --cc=bmasney@redhat.com \
    --cc=digetx@gmail.com \
    --cc=grandmaster@al2klimov.de \
    --cc=jonathanh@nvidia.com \
    --cc=justinstitt@google.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=mturquette@baylibre.com \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=pdeschrijver@nvidia.com \
    --cc=pgaikwad@nvidia.com \
    --cc=sboyd@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox