Skip to contentSkip to conversation

clk-Hisilicon: Fine-tuning for some function implementations

PATCH Applied SF Markus Elfring 2 participants 13 messages Apr 18, 2017 – Apr 19, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover clk-Hisilicon: Fine-tuning for some function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 11:27:32 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (6):
Use kcalloc() in hisi_clk_init()
Delete error messages for failed memory allocations in hisi_clk_init() Use devm_kmalloc_array() in hisi_clk_alloc()
Use kcalloc() in hi3620_mmc_clk_init()
Delete error messages for a failed memory allocation in two functions Fix a typo in one variable name

 drivers/clk/hisilicon/clk-hi3620.c | 16 ++++++----------
 drivers/clk/hisilicon/clk.c        | 18 ++++++++----------
 2 files changed, 14 insertions(+), 20 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/6 clk: hisilicon: Use kcalloc() in hisi_clk_init()

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 09:25:47 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/clk/hisilicon/clk.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/hisilicon/clk.c +1 -2
index 9ba2d91f4d3a..9268e80b7566 100644
@@ -85,8 +85,7 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 		goto err;
 	}
 	clk_data->base = base;
-
-	clk_table = kzalloc(sizeof(struct clk *) * nr_clks, GFP_KERNEL);
+	clk_table = kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL);
 	if (!clk_table) {
 		pr_err("%s: could not allocate clock lookup table\n", __func__);
 		goto err_data;
Signature · 1 line
2.12.2
Applied
#2 lore raw

Re: [PATCH 1/6] clk: hisilicon: Use kcalloc() in hisi_clk_init()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 09:25:47 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

Quoted 8 lines

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

PATCH 2/6 clk: hisilicon: Delete error messages for failed memory allocations in hisi_clk_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:12:32 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Possible unnecessary 'out of memory' message

Thus remove such statements here.

---
 drivers/clk/hisilicon/clk.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/clk/hisilicon/clk.c +4 -6
index 9268e80b7566..eca4c66e316c 100644
@@ -80,16 +80,14 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	}
 
 	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
-	if (!clk_data) {
-		pr_err("%s: could not allocate clock data\n", __func__);
+	if (!clk_data)
 		goto err;
-	}
+
 	clk_data->base = base;
 	clk_table = kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL);
-	if (!clk_table) {
-		pr_err("%s: could not allocate clock lookup table\n", __func__);
+	if (!clk_table)
 		goto err_data;
-	}
+
 	clk_data->clk_data.clks = clk_table;
 	clk_data->clk_data.clk_num = nr_clks;
 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
Signature · 1 line
2.12.2
Applied
#4 lore raw

Re: [PATCH 2/6] clk: hisilicon: Delete error messages for failed memory allocations in hisi_clk_init()

Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:12:32 +0200

The script "checkpatch.pl" pointed information out like the following.

Quoted 7 lines

WARNING: Possible unnecessary 'out of memory' message

Thus remove such statements here.

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#5 lore raw

PATCH 3/6 clk: hisilicon: Use devm_kmalloc_array() in hisi_clk_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:15:19 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/clk/hisilicon/clk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/hisilicon/clk.c +3 -2
index eca4c66e316c..b73c1dfae7f1 100644
@@ -54,8 +54,9 @@ struct hisi_clock_data *hisi_clk_alloc(struct platform_device *pdev,
 	if (!clk_data->base)
 		return NULL;
 
-	clk_table = devm_kmalloc(&pdev->dev, sizeof(struct clk *) * nr_clks,
-				GFP_KERNEL);
+	clk_table = devm_kmalloc_array(&pdev->dev, nr_clks,
+				       sizeof(*clk_table),
+				       GFP_KERNEL);
 	if (!clk_table)
 		return NULL;
 
Signature · 1 line
2.12.2
Applied
#6 lore raw

Re: [PATCH 3/6] clk: hisilicon: Use devm_kmalloc_array() in hisi_clk_alloc()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:15:19 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kmalloc_array".

Quoted 8 lines

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw

PATCH 4/6 clk: hi3620: Use kcalloc() in hi3620_mmc_clk_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:30:04 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/clk/hisilicon/clk-hi3620.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/hisilicon/clk-hi3620.c +1 -1
index d04a104ce1b4..f6dd971c9d3c 100644
@@ -482,7 +482,7 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
 	if (WARN_ON(!clk_data))
 		return;
 
-	clk_data->clks = kzalloc(sizeof(struct clk *) * num, GFP_KERNEL);
+	clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL);
 	if (!clk_data->clks) {
 		pr_err("%s: fail to allocate mmc clk\n", __func__);
 		return;
Signature · 1 line
2.12.2
Applied
#8 lore raw

Re: [PATCH 4/6] clk: hi3620: Use kcalloc() in hi3620_mmc_clk_init()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:30:04 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

Quoted 8 lines

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw

PATCH 5/6 clk: hi3620: Delete error messages for a failed memory allocation in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:50:53 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Possible unnecessary 'out of memory' message

Thus remove such statements here.

---
 drivers/clk/hisilicon/clk-hi3620.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/clk/hisilicon/clk-hi3620.c +2 -6
index f6dd971c9d3c..33a713ac8fe6 100644
@@ -430,10 +430,8 @@ static struct clk *hisi_register_clk_mmc(struct hisi_mmc_clock *mmc_clk,
 	struct clk_init_data init;
 
 	mclk = kzalloc(sizeof(*mclk), GFP_KERNEL);
-	if (!mclk) {
-		pr_err("%s: fail to allocate mmc clk\n", __func__);
+	if (!mclk)
 		return ERR_PTR(-ENOMEM);
-	}
 
 	init.name = mmc_clk->name;
 	init.ops = &clk_mmc_ops;
@@ -483,10 +481,8 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
 		return;
 
 	clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL);
-	if (!clk_data->clks) {
-		pr_err("%s: fail to allocate mmc clk\n", __func__);
+	if (!clk_data->clks)
 		return;
-	}
 
 	for (i = 0; i < num; i++) {
 		struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i];
Signature · 1 line
2.12.2
Applied
#10 lore raw

Re: [PATCH 5/6] clk: hi3620: Delete error messages for a failed memory allocation in two functions

Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 10:50:53 +0200

The script "checkpatch.pl" pointed information out like the following.

Quoted 7 lines

WARNING: Possible unnecessary 'out of memory' message

Thus remove such statements here.

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#11 lore raw

PATCH 6/6 clk: hi3620: Fix a typo in one variable name

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 11:15:56 +0200

The script "checkpatch.pl" pointed information out like the following.

CHECK: 'seperated' may be misspelled - perhaps 'separated'?

Thus rename the affected variable.

---
 drivers/clk/hisilicon/clk-hi3620.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/hisilicon/clk-hi3620.c +3 -3
index 33a713ac8fe6..fa0fba653898 100644
@@ -144,7 +144,7 @@ static struct hisi_divider_clock hi3620_div_clks[] __initdata = {
 	{ HI3620_MMC3_DIV,     "mmc3_div",   "mmc3_mux",  0, 0x140, 5, 4, CLK_DIVIDER_HIWORD_MASK, NULL, },
 };
 
-static struct hisi_gate_clock hi3620_seperated_gate_clks[] __initdata = {
+static struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata = {
 	{ HI3620_TIMERCLK01,   "timerclk01",   "timer_rclk01", CLK_SET_RATE_PARENT, 0x20, 0, 0, },
 	{ HI3620_TIMER_RCLK01, "timer_rclk01", "rclk_tcxo",    CLK_SET_RATE_PARENT, 0x20, 1, 0, },
 	{ HI3620_TIMERCLK23,   "timerclk23",   "timer_rclk23", CLK_SET_RATE_PARENT, 0x20, 2, 0, },
@@ -224,8 +224,8 @@ static void __init hi3620_clk_init(struct device_node *np)
 			      clk_data);
 	hisi_clk_register_divider(hi3620_div_clks, ARRAY_SIZE(hi3620_div_clks),
 				  clk_data);
-	hisi_clk_register_gate_sep(hi3620_seperated_gate_clks,
-				   ARRAY_SIZE(hi3620_seperated_gate_clks),
+	hisi_clk_register_gate_sep(hi3620_separated_gate_clks,
+				   ARRAY_SIZE(hi3620_separated_gate_clks),
 				   clk_data);
 }
 CLK_OF_DECLARE(hi3620_clk, "hisilicon,hi3620-clock", hi3620_clk_init);
Signature · 1 line
2.12.2
Applied
#12 lore raw

Re: [PATCH 6/6] clk: hi3620: Fix a typo in one variable name

Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Apr 2017 11:15:56 +0200

The script "checkpatch.pl" pointed information out like the following.

CHECK: 'seperated' may be misspelled - perhaps 'separated'?

Thus rename the affected variable.

---

Applied to clk-next

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project