linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhen Lei <thunder.leizhen@huawei.com>
To: Peter De Schrijver <pdeschrijver@nvidia.com>,
	Prashant Gaikwad <pgaikwad@nvidia.com>,
	Michael Turquette <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	"Jonathan Hunter" <jonathanh@nvidia.com>,
	Dmitry Osipenko <digetx@gmail.com>,
	linux-clk <linux-clk@vger.kernel.org>,
	linux-tegra <linux-tegra@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Subject: [PATCH 1/1] clk: tegra: tegra124-emc: Fix possible memory leak
Date: Thu, 17 Jun 2021 16:27:59 +0800	[thread overview]
Message-ID: <20210617082759.1008-1-thunder.leizhen@huawei.com> (raw)

When krealloc() fails to expand the memory and returns NULL, the original
memory is not released. In this case, the original "timings" scale should
be maintained.

Fixes: 888ca40e2843 ("clk: tegra: emc: Support multiple RAM codes")
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/clk/tegra/clk-tegra124-emc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
index 74c1d894cca8..1a329202b543 100644
--- a/drivers/clk/tegra/clk-tegra124-emc.c
+++ b/drivers/clk/tegra/clk-tegra124-emc.c
@@ -450,11 +450,12 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
 
 	size = (tegra->num_timings + child_count) * sizeof(struct emc_timing);
 
-	tegra->timings = krealloc(tegra->timings, size, GFP_KERNEL);
-	if (!tegra->timings)
+	timings_ptr = krealloc(tegra->timings, size, GFP_KERNEL);
+	if (!timings_ptr)
 		return -ENOMEM;
 
-	timings_ptr = tegra->timings + tegra->num_timings;
+	tegra->timings = timings_ptr;
+	timings_ptr += tegra->num_timings;
 	tegra->num_timings += child_count;
 
 	for_each_child_of_node(node, child) {
-- 
2.25.1



             reply	other threads:[~2021-06-17  8:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17  8:27 Zhen Lei [this message]
2021-06-25 23:31 ` [PATCH 1/1] clk: tegra: tegra124-emc: Fix possible memory leak Stephen Boyd
2021-06-26  1:32   ` Leizhen (ThunderTown)
2021-06-27 23:44     ` Stephen Boyd
2021-06-28  0:29       ` Dmitry Osipenko
2021-06-28  1:52         ` Stephen Boyd

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=20210617082759.1008-1-thunder.leizhen@huawei.com \
    --to=thunder.leizhen@huawei.com \
    --cc=digetx@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=pdeschrijver@nvidia.com \
    --cc=pgaikwad@nvidia.com \
    --cc=sboyd@kernel.org \
    --cc=thierry.reding@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).