[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210617082759.1008-1-thunder.leizhen@huawei.com>
Date: Thu, 17 Jun 2021 16:27:59 +0800
From: Zhen Lei <thunder.leizhen@...wei.com>
To: Peter De Schrijver <pdeschrijver@...dia.com>,
Prashant Gaikwad <pgaikwad@...dia.com>,
Michael Turquette <mturquette@...libre.com>,
"Stephen Boyd" <sboyd@...nel.org>,
Thierry Reding <thierry.reding@...il.com>,
"Jonathan Hunter" <jonathanh@...dia.com>,
Dmitry Osipenko <digetx@...il.com>,
linux-clk <linux-clk@...r.kernel.org>,
linux-tegra <linux-tegra@...r.kernel.org>,
linux-kernel <linux-kernel@...r.kernel.org>
CC: Zhen Lei <thunder.leizhen@...wei.com>
Subject: [PATCH 1/1] clk: tegra: tegra124-emc: Fix possible memory leak
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@...wei.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
Powered by blists - more mailing lists