2017-04-20 08:21:24

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/8] clk: Fine-tuning for ten function implementations

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 10:12:34 +0200

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

Markus Elfring (8):
Use devm_kcalloc() in si5351_i2c_probe()
Delete an error message for a failed memory allocation in si5351_i2c_probe()
Adjust a null pointer check in si5351_dt_parse()
Replace four seq_printf() calls by seq_putc()
Combine two seq_puts() calls into one call in clk_summary_show()
Improve a size determination in two functions
Use seq_puts() in nomadik_src_clk_show()
Delete error messages for a failed memory allocation in two functions

drivers/clk/clk-nomadik.c | 12 ++++--------
drivers/clk/clk-si5351.c | 10 ++++------
drivers/clk/clk.c | 19 +++++++++----------
3 files changed, 17 insertions(+), 24 deletions(-)

--
2.12.2


2017-04-20 08:22:23

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/8] clk: si5351: Use devm_kcalloc() in si5351_i2c_probe()

From: Markus Elfring <[email protected]>
Date: Wed, 19 Apr 2017 22:37:30 +0200

Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

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

diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index b051db43fae1..a4c009e1e70d 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1535,9 +1535,9 @@ static int si5351_i2c_probe(struct i2c_client *client,
else
parent_names[1] = si5351_pll_names[1];

- drvdata->msynth = devm_kzalloc(&client->dev, num_clocks *
+ drvdata->msynth = devm_kcalloc(&client->dev, num_clocks,
sizeof(*drvdata->msynth), GFP_KERNEL);
- drvdata->clkout = devm_kzalloc(&client->dev, num_clocks *
+ drvdata->clkout = devm_kcalloc(&client->dev, num_clocks,
sizeof(*drvdata->clkout), GFP_KERNEL);
drvdata->num_clkout = num_clocks;

--
2.12.2

2017-04-20 08:23:59

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/8] clk: si5351: Delete an error message for a failed memory allocation in si5351_i2c_probe()

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 07:34:54 +0200

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

* CHECK: Comparison to NULL could be written "!drvdata"

Thus adjust this expression.


* WARNING: Possible unnecessary 'out of memory' message

Thus remove such a statement 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/clk-si5351.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index a4c009e1e70d..2492442eea77 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1354,10 +1354,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
return -EINVAL;

drvdata = devm_kzalloc(&client->dev, sizeof(*drvdata), GFP_KERNEL);
- if (drvdata == NULL) {
- dev_err(&client->dev, "unable to allocate driver data\n");
+ if (!drvdata)
return -ENOMEM;
- }

i2c_set_clientdata(client, drvdata);
drvdata->client = client;
--
2.12.2

2017-04-20 08:26:18

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/8] clk: si5351: Adjust a null pointer check in si5351_dt_parse()

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 07:47:04 +0200

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

Comparison to NULL could be written "!np".

Thus adjust this expression.

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

diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index 2492442eea77..a0acea67b571 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1140,7 +1140,7 @@ static int si5351_dt_parse(struct i2c_client *client,
int num = 0;
u32 val;

- if (np == NULL)
+ if (!np)
return 0;

pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
--
2.12.2

2017-04-20 08:27:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/8] clk: Replace four seq_printf() calls by seq_putc()

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 08:45:43 +0200

Four single characters should be put into a sequence.
Thus use the corresponding function "seq_putc".

This issue was detected by using the Coccinelle software.

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

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 67201f67a14a..4c72a10a9a33 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2081,11 +2081,11 @@ static void clk_dump_subtree(struct seq_file *s, struct clk_core *c, int level)
clk_dump_one(s, c, level);

hlist_for_each_entry(child, &c->children, child_node) {
- seq_printf(s, ",");
+ seq_putc(s, ',');
clk_dump_subtree(s, child, level + 1);
}

- seq_printf(s, "}");
+ seq_putc(s, '}');
}

static int clk_dump(struct seq_file *s, void *data)
@@ -2094,14 +2094,13 @@ static int clk_dump(struct seq_file *s, void *data)
bool first_node = true;
struct hlist_head **lists = (struct hlist_head **)s->private;

- seq_printf(s, "{");
-
+ seq_putc(s, '{');
clk_prepare_lock();

for (; *lists; lists++) {
hlist_for_each_entry(c, *lists, child_node) {
if (!first_node)
- seq_puts(s, ",");
+ seq_putc(s, ',');
first_node = false;
clk_dump_subtree(s, c, 0);
}
--
2.12.2

2017-04-20 08:29:18

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/8] clk: Combine two seq_puts() calls into one call in clk_summary_show()

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 09:12:35 +0200

Some text was put into a sequence by two separate function calls.
Print the same data by a single function call instead.

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

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 4c72a10a9a33..684642ab4212 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2030,9 +2030,9 @@ static int clk_summary_show(struct seq_file *s, void *data)
struct clk_core *c;
struct hlist_head **lists = (struct hlist_head **)s->private;

- seq_puts(s, " clock enable_cnt prepare_cnt rate accuracy phase\n");
- seq_puts(s, "----------------------------------------------------------------------------------------\n");
-
+ seq_puts(s,
+ " clock enable_cnt prepare_cnt rate accuracy phase\n"
+ "----------------------------------------------------------------------------------------\n");
clk_prepare_lock();

for (; *lists; lists++)
--
2.12.2

2017-04-20 08:30:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/8] clk: Improve a size determination in two functions

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 09:30:52 +0200

Replace the specification of two data structures by pointer dereferences
as the parameter for the operator "sizeof" 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/clk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 684642ab4212..3f2ee0469d3e 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2939,7 +2939,7 @@ int clk_notifier_register(struct clk *clk, struct notifier_block *nb)

/* if clk wasn't in the notifier list, allocate new clk_notifier */
if (cn->clk != clk) {
- cn = kzalloc(sizeof(struct clk_notifier), GFP_KERNEL);
+ cn = kzalloc(sizeof(*cn), GFP_KERNEL);
if (!cn)
goto out;

@@ -3087,7 +3087,7 @@ int of_clk_add_provider(struct device_node *np,
struct of_clk_provider *cp;
int ret;

- cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
+ cp = kzalloc(sizeof(*cp), GFP_KERNEL);
if (!cp)
return -ENOMEM;

--
2.12.2

2017-04-20 08:30:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 7/8] clk: nomadik: Use seq_puts() in nomadik_src_clk_show()

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 09:45:04 +0200

A string which did not contain a data format specification should be put
into a sequence. Thus use the corresponding function "seq_puts".

This issue was detected by using the Coccinelle software.

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

diff --git a/drivers/clk/clk-nomadik.c b/drivers/clk/clk-nomadik.c
index 71677eb12565..8d57ab8d6ed8 100644
--- a/drivers/clk/clk-nomadik.c
+++ b/drivers/clk/clk-nomadik.c
@@ -467,7 +467,7 @@ static int nomadik_src_clk_show(struct seq_file *s, void *what)
u32 src_pckensr0 = readl(src_base + SRC_PCKENSR0);
u32 src_pckensr1 = readl(src_base + SRC_PCKENSR1);

- seq_printf(s, "Clock: Boot: Now: Request: ASKED:\n");
+ seq_puts(s, "Clock: Boot: Now: Request: ASKED:\n");
for (i = 0; i < ARRAY_SIZE(src_clk_names); i++) {
u32 pcksrb = (i < 0x20) ? src_pcksr0_boot : src_pcksr1_boot;
u32 pcksr = (i < 0x20) ? src_pcksr0 : src_pcksr1;
--
2.12.2

2017-04-20 08:32:30

by SF Markus Elfring

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

From: Markus Elfring <[email protected]>
Date: Thu, 20 Apr 2017 10:04:00 +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/clk-nomadik.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/clk-nomadik.c b/drivers/clk/clk-nomadik.c
index 8d57ab8d6ed8..13ad6d1e5090 100644
--- a/drivers/clk/clk-nomadik.c
+++ b/drivers/clk/clk-nomadik.c
@@ -267,10 +267,8 @@ pll_clk_register(struct device *dev, const char *name,
}

pll = kzalloc(sizeof(*pll), GFP_KERNEL);
- if (!pll) {
- pr_err("%s: could not allocate PLL clk\n", __func__);
+ if (!pll)
return ERR_PTR(-ENOMEM);
- }

init.name = name;
init.ops = &pll_clk_ops;
@@ -356,11 +354,9 @@ src_clk_register(struct device *dev, const char *name,
struct clk_init_data init;

sclk = kzalloc(sizeof(*sclk), GFP_KERNEL);
- if (!sclk) {
- pr_err("could not allocate SRC clock %s\n",
- name);
+ if (!sclk)
return ERR_PTR(-ENOMEM);
- }
+
init.name = name;
init.ops = &src_clk_ops;
/* Do not force-disable the static SDRAM controller */
--
2.12.2

2017-04-22 02:44:48

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 1/8] clk: si5351: Use devm_kcalloc() in si5351_i2c_probe()

On 04/20, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Wed, 19 Apr 2017 22:37:30 +0200
>
> Multiplications for the size determination of memory allocations
> indicated that array data structures should be processed.
> Thus use the corresponding function "devm_kcalloc".
>
> This issue was detected by using the Coccinelle software.
>
> 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-22 02:45:28

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 2/8] clk: si5351: Delete an error message for a failed memory allocation in si5351_i2c_probe()

On 04/20, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 20 Apr 2017 07:34:54 +0200
>
> The script "checkpatch.pl" pointed information out like the following.
>
> * CHECK: Comparison to NULL could be written "!drvdata"
>
> Thus adjust this expression.
>
>
> * WARNING: Possible unnecessary 'out of memory' message
>
> Thus remove such a statement 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-22 02:46:21

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 4/8] clk: Replace four seq_printf() calls by seq_putc()

On 04/20, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 20 Apr 2017 08:45:43 +0200
>
> Four single characters should be put into a sequence.
> Thus use the corresponding function "seq_putc".
>
> This issue was detected by using the Coccinelle software.
>
> 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-22 02:48:24

by Stephen Boyd

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

On 04/20, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 20 Apr 2017 10:04:00 +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-22 02:47:08

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 6/8] clk: Improve a size determination in two functions

On 04/20, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 20 Apr 2017 09:30:52 +0200
>
> Replace the specification of two data structures by pointer dereferences
> as the parameter for the operator "sizeof" 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-22 02:48:36

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 7/8] clk: nomadik: Use seq_puts() in nomadik_src_clk_show()

On 04/20, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 20 Apr 2017 09:45:04 +0200
>
> A string which did not contain a data format specification should be put
> into a sequence. Thus use the corresponding function "seq_puts".
>
> This issue was detected by using the Coccinelle software.
>
> 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