Skip to contentSkip to conversation

clk: fix memory leak in hisi_clk_init.

PATCH In review Tao Lan 2 participants 2 messages Dec 22, 2022 – Aug 13, 2023 Common clk

lore
Share & tools
lore

Tao Lan

author
#0 lore raw

PATCH 1/1 clk: fix memory leak in hisi_clk_init.

From: taolan <[email protected]>

when clk_data create fail, we also need to release base.

---
 drivers/clk/hisilicon/clk.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clk/hisilicon/clk.c +4 -0
index 54d9fdc93599..9ca4fc05fa57 100644
@@ -82,6 +82,10 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
 	return clk_data;
 err_data:
+	if (base) {
+		iounmap(base);
+		base = NULL;
+	}
 	kfree(clk_data);
 err:
 	return NULL;
Signature · 1 line
2.17.1
#1 lore raw

Hello,

sorry for the delay, but I found this unmerged patch while cleaning up my mailbox.

Quoted 14 lines · Tao Lan

From: taolan <[email protected]>

when clk_data create fail, we also need to release base.

---
 drivers/clk/hisilicon/clk.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/clk/hisilicon/clk.c +0 -0
index 54d9fdc93599..9ca4fc05fa57 100644

drivers/clk/hisilicon/clk.c struct hisi_clock_data *hisi_clk_init(struct device_node *np, · line 88

Quoted 7 lines
drivers/clk/hisilicon/clk.c +4 -0
@@ -82,6 +82,10 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
 	return clk_data;
 err_data:
+	if (base) {
+		iounmap(base);
+		base = NULL;
+	}

This is inaccurate. Consider the case when kzalloc fails:

	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
	if (!clk_data)
		goto err;

base has already been mapped, but the code jumps to 'err', which doesn't have the iounmap.

To address this properly, you'd have to add another label between err_data and err.

drivers/clk/hisilicon/clk.c struct hisi_clock_data *hisi_clk_init(struct device_node *np, · line 91

Quoted 3 lines
drivers/clk/hisilicon/clk.c +0 -0
 	kfree(clk_data);
 err:
 	return NULL;

Best regards,
jn