Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: hi3620: Fix memory leak in hi3620_mmc_clk_init()

In cases where kcalloc() fails for the 'clk_data->clks' allocation, the
code path does not handle the failure gracefully, potentially leading
to a memory leak. This fix ensures proper cleanup by freeing the
allocated memory for 'clk_data' before returning.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Link: https://lore.kernel.org/r/20231210165040.3407545-1-visitorckw@gmail.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Kuan-Wei Chiu and committed by
Stephen Boyd
bfbea9e5 1004c346

+3 -1
+3 -1
drivers/clk/hisilicon/clk-hi3620.c
··· 466 466 return; 467 467 468 468 clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL); 469 - if (!clk_data->clks) 469 + if (!clk_data->clks) { 470 + kfree(clk_data); 470 471 return; 472 + } 471 473 472 474 for (i = 0; i < num; i++) { 473 475 struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i];