Skip to content

Commit bfbea9e

Browse files
visitorckwbebarino
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 1004c34 commit bfbea9e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/clk/hisilicon/clk-hi3620.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,10 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
466466
return;
467467

468468
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);
470471
return;
472+
}
471473

472474
for (i = 0; i < num; i++) {
473475
struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i];

0 commit comments

Comments
 (0)