Skip to contentSkip to conversation

clk: hisilicon: Improve deallocation in error path

PATCH Applied J. Neuschäfer 3 participants 5 messages Mar 3 – Apr 29 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clk: hisilicon: Improve deallocation in error path

Unmap 'base' if an error occurs after it has been mapped.

---
Changes in v2:
- Rebase on v7.0-rc2
- Update my email address
- Reword the commit message somewhat
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/clk/hisilicon/clk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/hisilicon/clk.c +3 -1
index fae65127cd4aa8..08050ff1c8cf9a 100644
@@ -70,7 +70,7 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 
 	clk_data = kzalloc_obj(*clk_data);
 	if (!clk_data)
-		goto err;
+		goto err_base;
 
 	clk_data->base = base;
 	clk_table = kzalloc_objs(*clk_table, nr_clks);
@@ -83,6 +83,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	return clk_data;
 err_data:
 	kfree(clk_data);
+err_base:
+	iounmap(base);
 err:
 	return NULL;
 }

---
base-commit: 11439c4635edd669ae435eec308f4ab8a0804808
change-id: 20240329-hisi-error-c00ad7f8dd72

Best regards,

Signature · 1 line
J. Neuschäfer <[email protected]>
#1 lore raw
Quoted 7 lines · On Tue, Mar 03, 2026 at 04:25:18PM +0100, J. Neuschäfer via B4 Relay wrote:

From: "J. Neuschäfer" <[email protected]>

Unmap 'base' if an error occurs after it has been mapped.

My understanding is that you need to use your full first name in the Signed-off-by.

Quoted 24 lines

---
Changes in v2:
- Rebase on v7.0-rc2
- Update my email address
- Reword the commit message somewhat
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/clk/hisilicon/clk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/hisilicon/clk.c +1 -1
index fae65127cd4aa8..08050ff1c8cf9a 100644
@@ -70,7 +70,7 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 
 	clk_data = kzalloc_obj(*clk_data);
 	if (!clk_data)
-		goto err;
+		goto err_base;
 
 	clk_data->base = base;
 	clk_table = kzalloc_objs(*clk_table, nr_clks);

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

Quoted 5 lines
drivers/clk/hisilicon/clk.c +2 -0
@@ -83,6 +83,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	return clk_data;
 err_data:
 	kfree(clk_data);
+err_base:
+	iounmap(base);

Use devm_of_iomap() and it will be automatically cleaned up for you.

Brian

#2 lore raw
Quoted 11 lines · Brian Masney
Quoted 7 lines · On Tue, Mar 03, 2026 at 04:25:18PM +0100, J. Neuschäfer via B4 Relay wrote:

From: "J. Neuschäfer" <[email protected]>

Unmap 'base' if an error occurs after it has been mapped.

My understanding is that you need to use your full first name in the Signed-off-by.

I have been contributing to the Linux kernel and other projects using my abbreviated first name for over a year. It has been mostly well received.

Quoted 22 lines
Quoted 22 lines

---
Changes in v2:
- Rebase on v7.0-rc2
- Update my email address
- Reword the commit message somewhat
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/clk/hisilicon/clk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/hisilicon/clk.c +1 -1
index fae65127cd4aa8..08050ff1c8cf9a 100644
@@ -70,7 +70,7 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 
 	clk_data = kzalloc_obj(*clk_data);
 	if (!clk_data)
-		goto err;
+		goto err_base;
 
Quoted 10 lines

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

Quoted 8 lines
drivers/clk/hisilicon/clk.c +2 -0
 	clk_data->base = base;
 	clk_table = kzalloc_objs(*clk_table, nr_clks);
@@ -83,6 +83,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	return clk_data;
 err_data:
 	kfree(clk_data);
+err_base:
+	iounmap(base);

Use devm_of_iomap() and it will be automatically cleaned up for you.

This would require a larger restructuring of the HiSilicon clock drivers to pass a struct device * to hisi_clk_init. I'd rather avoid that because I can't currently test these drivers and because the benefit is questionable. However, I still had the upstreaming of this patch in my backlog, and I think it's simple enough to review as is.

For instance, in drivers/clk/hisilicon/clk-hi3620.c:

static void __init hi3620_clk_init(struct device_node *np)

{
	struct hisi_clock_data *clk_data;

	clk_data = hisi_clk_init(np, HI3620_NR_CLKS);
	...
}

CLK_OF_DECLARE(hi3620_clk, "hisilicon,hi3620-clock", hi3620_clk_init);

Init functions registered with CLK_OF_DECLARE don't have access to a struct device *.

Best regards,
J. Neuschäfer

Reviewed-by
#3 lore raw
Quoted 10 lines · J. Neuschäfer
Quoted 9 lines · Brian Masney
Quoted 7 lines · On Tue, Mar 03, 2026 at 04:25:18PM +0100, J. Neuschäfer via B4 Relay wrote:

From: "J. Neuschäfer" <[email protected]>

Unmap 'base' if an error occurs after it has been mapped.

Quoted 5 lines
Quoted 2 lines

My understanding is that you need to use your full first name in the Signed-off-by.

I have been contributing to the Linux kernel and other projects using my abbreviated first name for over a year. It has been mostly well received.

Sorry I should have checked.

Quoted 31 lines
Quoted 20 lines
Quoted 20 lines

Changes in v2:
- Rebase on v7.0-rc2
- Update my email address
- Reword the commit message somewhat
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/clk/hisilicon/clk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/hisilicon/clk.c +1 -1
index fae65127cd4aa8..08050ff1c8cf9a 100644
@@ -70,7 +70,7 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 
 	clk_data = kzalloc_obj(*clk_data);
 	if (!clk_data)
-		goto err;
+		goto err_base;
 
Quoted 10 lines

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

Quoted 8 lines
drivers/clk/hisilicon/clk.c +2 -0
 	clk_data->base = base;
 	clk_table = kzalloc_objs(*clk_table, nr_clks);
@@ -83,6 +83,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	return clk_data;
 err_data:
 	kfree(clk_data);
+err_base:
+	iounmap(base);

Use devm_of_iomap() and it will be automatically cleaned up for you.

Quoted 5 lines

This would require a larger restructuring of the HiSilicon clock drivers to pass a struct device * to hisi_clk_init. I'd rather avoid that because I can't currently test these drivers and because the benefit is questionable. However, I still had the upstreaming of this patch in my backlog, and I think it's simple enough to review as is.

OK, fair enough.