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@xxxxxxxxxx> --- 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