2017-04-18 09:35:43

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/6] 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(-)

--
2.12.2


2017-04-18 09:38:02

by SF Markus Elfring

[permalink] [raw]
Subject: [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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/hisilicon/clk.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
index 9ba2d91f4d3a..9268e80b7566 100644
--- a/drivers/clk/hisilicon/clk.c
+++ b/drivers/clk/hisilicon/clk.c
@@ -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;
--
2.12.2

2017-04-18 09:39:40

by SF Markus Elfring

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

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.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/hisilicon/clk.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
index 9268e80b7566..eca4c66e316c 100644
--- a/drivers/clk/hisilicon/clk.c
+++ b/drivers/clk/hisilicon/clk.c
@@ -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);
--
2.12.2

2017-04-18 09:41:17

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/6] clk: hisilicon: Use devm_kmalloc_array() in hisi_clk_alloc()

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/hisilicon/clk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
index eca4c66e316c..b73c1dfae7f1 100644
--- a/drivers/clk/hisilicon/clk.c
+++ b/drivers/clk/hisilicon/clk.c
@@ -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;

--
2.12.2

2017-04-18 09:42:29

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/6] clk: hi3620: Use kcalloc() in hi3620_mmc_clk_init()

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/hisilicon/clk-hi3620.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c
index d04a104ce1b4..f6dd971c9d3c 100644
--- a/drivers/clk/hisilicon/clk-hi3620.c
+++ b/drivers/clk/hisilicon/clk-hi3620.c
@@ -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;
--
2.12.2

2017-04-18 09:45:04

by SF Markus Elfring

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

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.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/hisilicon/clk-hi3620.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c
index f6dd971c9d3c..33a713ac8fe6 100644
--- a/drivers/clk/hisilicon/clk-hi3620.c
+++ b/drivers/clk/hisilicon/clk-hi3620.c
@@ -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];
--
2.12.2

2017-04-18 09:45:02

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/6] clk: hi3620: Fix a typo in one variable name

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/hisilicon/clk-hi3620.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c
index 33a713ac8fe6..fa0fba653898 100644
--- a/drivers/clk/hisilicon/clk-hi3620.c
+++ b/drivers/clk/hisilicon/clk-hi3620.c
@@ -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);
--
2.12.2

2017-04-19 18:31:39

by Stephen Boyd

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

On 04/18, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-04-19 18:31:47

by Stephen Boyd

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

On 04/18, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-04-19 18:31:56

by Stephen Boyd

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

On 04/18, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-04-19 18:32:08

by Stephen Boyd

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

On 04/18, SF Markus Elfring wrote:
> 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.
>
> Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
> Signed-off-by: Markus Elfring <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-04-19 18:32:53

by Stephen Boyd

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

On 04/18, SF Markus Elfring wrote:
> 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.
>
> Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
> Signed-off-by: Markus Elfring <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-04-19 18:32:51

by Stephen Boyd

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

On 04/18, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project