2017-09-27 07:23:46

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] MMP clock: Adjustments for seven function implementations

From: Markus Elfring <[email protected]>
Date: Wed, 27 Sep 2017 09:21:23 +0200

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

Markus Elfring (3):
Delete an error message for a failed memory allocation in three functions
Use common error handling code in mmp_clk_register_mix()
Adjust 12 checks for null pointers

drivers/clk/mmp/clk-frac.c | 4 +---
drivers/clk/mmp/clk-gate.c | 4 +---
drivers/clk/mmp/clk-mix.c | 27 +++++++++++----------------
drivers/clk/mmp/clk-mmp2.c | 6 +++---
drivers/clk/mmp/clk-pxa168.c | 6 +++---
drivers/clk/mmp/clk-pxa910.c | 8 ++++----
6 files changed, 23 insertions(+), 32 deletions(-)

--
2.14.1


2017-09-27 07:25:17

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] clk/mmp: Delete an error message for a failed memory allocation in three functions

From: Markus Elfring <[email protected]>
Date: Tue, 26 Sep 2017 22:25:38 +0200

Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/mmp/clk-frac.c | 4 +---
drivers/clk/mmp/clk-gate.c | 4 +---
drivers/clk/mmp/clk-mix.c | 9 +--------
3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/clk/mmp/clk-frac.c b/drivers/clk/mmp/clk-frac.c
index 584a9927993b..98dfb9568d4f 100644
--- a/drivers/clk/mmp/clk-frac.c
+++ b/drivers/clk/mmp/clk-frac.c
@@ -172,10 +172,8 @@ struct clk *mmp_clk_register_factor(const char *name, const char *parent_name,
}

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

/* struct clk_aux assignments */
factor->base = base;
diff --git a/drivers/clk/mmp/clk-gate.c b/drivers/clk/mmp/clk-gate.c
index d20cd3431ac2..7355595c42e2 100644
--- a/drivers/clk/mmp/clk-gate.c
+++ b/drivers/clk/mmp/clk-gate.c
@@ -103,10 +103,8 @@ struct clk *mmp_clk_register_gate(struct device *dev, const char *name,

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

init.name = name;
init.ops = &mmp_clk_gate_ops;
diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c
index c554833cffc5..1ae532df20f7 100644
--- a/drivers/clk/mmp/clk-mix.c
+++ b/drivers/clk/mmp/clk-mix.c
@@ -451,11 +451,8 @@ struct clk *mmp_clk_register_mix(struct device *dev,
size_t table_bytes;

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

init.name = name;
init.flags = flags | CLK_GET_RATE_NOCACHE;
@@ -468,8 +465,6 @@ struct clk *mmp_clk_register_mix(struct device *dev,
table_bytes = sizeof(*config->table) * config->table_size;
mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL);
if (!mix->table) {
- pr_err("%s:%s: could not allocate mmp mix table\n",
- __func__, name);
kfree(mix);
return ERR_PTR(-ENOMEM);
}
@@ -481,8 +476,6 @@ struct clk *mmp_clk_register_mix(struct device *dev,
mix->mux_table = kmemdup(config->mux_table, table_bytes,
GFP_KERNEL);
if (!mix->mux_table) {
- pr_err("%s:%s: could not allocate mmp mix mux-table\n",
- __func__, name);
kfree(mix->table);
kfree(mix);
return ERR_PTR(-ENOMEM);
--
2.14.1

2017-09-27 07:26:34

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] clk/mmp: Use common error handling code in mmp_clk_register_mix()

From: Markus Elfring <[email protected]>
Date: Tue, 26 Sep 2017 22:33:18 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

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

diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c
index 1ae532df20f7..b2471fb369f1 100644
--- a/drivers/clk/mmp/clk-mix.c
+++ b/drivers/clk/mmp/clk-mix.c
@@ -464,10 +464,9 @@ struct clk *mmp_clk_register_mix(struct device *dev,
if (config->table) {
table_bytes = sizeof(*config->table) * config->table_size;
mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL);
- if (!mix->table) {
- kfree(mix);
- return ERR_PTR(-ENOMEM);
- }
+ if (!mix->table)
+ goto free_mix;
+
mix->table_size = config->table_size;
}

@@ -477,8 +476,7 @@ struct clk *mmp_clk_register_mix(struct device *dev,
GFP_KERNEL);
if (!mix->mux_table) {
kfree(mix->table);
- kfree(mix);
- return ERR_PTR(-ENOMEM);
+ goto free_mix;
}
}

@@ -502,4 +500,8 @@ struct clk *mmp_clk_register_mix(struct device *dev,
}

return clk;
+
+free_mix:
+ kfree(mix);
+ return ERR_PTR(-ENOMEM);
}
--
2.14.1

2017-09-27 07:27:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] clk/mmp: Adjust 12 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Wed, 27 Sep 2017 09:00:21 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/clk/mmp/clk-mix.c | 4 ++--
drivers/clk/mmp/clk-mmp2.c | 6 +++---
drivers/clk/mmp/clk-pxa168.c | 6 +++---
drivers/clk/mmp/clk-pxa910.c | 8 ++++----
4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c
index b2471fb369f1..90814b2613c0 100644
--- a/drivers/clk/mmp/clk-mix.c
+++ b/drivers/clk/mmp/clk-mix.c
@@ -229,7 +229,7 @@ static int mmp_clk_mix_determine_rate(struct clk_hw *hw,
parent_rate = clk_hw_get_rate(parent);
mix_rate = parent_rate / item->divisor;
gap = abs(mix_rate - req->rate);
- if (parent_best == NULL || gap < gap_best) {
+ if (!parent_best || gap < gap_best) {
parent_best = parent;
parent_rate_best = parent_rate;
mix_rate_best = mix_rate;
@@ -247,7 +247,7 @@ static int mmp_clk_mix_determine_rate(struct clk_hw *hw,
div = _get_div(mix, j);
mix_rate = parent_rate / div;
gap = abs(mix_rate - req->rate);
- if (parent_best == NULL || gap < gap_best) {
+ if (!parent_best || gap < gap_best) {
parent_best = parent;
parent_rate_best = parent_rate;
mix_rate_best = mix_rate;
diff --git a/drivers/clk/mmp/clk-mmp2.c b/drivers/clk/mmp/clk-mmp2.c
index 038023483b98..7460031714da 100644
--- a/drivers/clk/mmp/clk-mmp2.c
+++ b/drivers/clk/mmp/clk-mmp2.c
@@ -83,19 +83,19 @@ void __init mmp2_clk_init(phys_addr_t mpmu_phys, phys_addr_t apmu_phys,
void __iomem *apbc_base;

mpmu_base = ioremap(mpmu_phys, SZ_4K);
- if (mpmu_base == NULL) {
+ if (!mpmu_base) {
pr_err("error to ioremap MPMU base\n");
return;
}

apmu_base = ioremap(apmu_phys, SZ_4K);
- if (apmu_base == NULL) {
+ if (!apmu_base) {
pr_err("error to ioremap APMU base\n");
return;
}

apbc_base = ioremap(apbc_phys, SZ_4K);
- if (apbc_base == NULL) {
+ if (!apbc_base) {
pr_err("error to ioremap APBC base\n");
return;
}
diff --git a/drivers/clk/mmp/clk-pxa168.c b/drivers/clk/mmp/clk-pxa168.c
index a9ef9209532a..8e2551ab8462 100644
--- a/drivers/clk/mmp/clk-pxa168.c
+++ b/drivers/clk/mmp/clk-pxa168.c
@@ -75,19 +75,19 @@ void __init pxa168_clk_init(phys_addr_t mpmu_phys, phys_addr_t apmu_phys,
void __iomem *apbc_base;

mpmu_base = ioremap(mpmu_phys, SZ_4K);
- if (mpmu_base == NULL) {
+ if (!mpmu_base) {
pr_err("error to ioremap MPMU base\n");
return;
}

apmu_base = ioremap(apmu_phys, SZ_4K);
- if (apmu_base == NULL) {
+ if (!apmu_base) {
pr_err("error to ioremap APMU base\n");
return;
}

apbc_base = ioremap(apbc_phys, SZ_4K);
- if (apbc_base == NULL) {
+ if (!apbc_base) {
pr_err("error to ioremap APBC base\n");
return;
}
diff --git a/drivers/clk/mmp/clk-pxa910.c b/drivers/clk/mmp/clk-pxa910.c
index a520cf7702a1..7a7965141918 100644
--- a/drivers/clk/mmp/clk-pxa910.c
+++ b/drivers/clk/mmp/clk-pxa910.c
@@ -74,25 +74,25 @@ void __init pxa910_clk_init(phys_addr_t mpmu_phys, phys_addr_t apmu_phys,
void __iomem *apbc_base;

mpmu_base = ioremap(mpmu_phys, SZ_4K);
- if (mpmu_base == NULL) {
+ if (!mpmu_base) {
pr_err("error to ioremap MPMU base\n");
return;
}

apmu_base = ioremap(apmu_phys, SZ_4K);
- if (apmu_base == NULL) {
+ if (!apmu_base) {
pr_err("error to ioremap APMU base\n");
return;
}

apbcp_base = ioremap(apbcp_phys, SZ_4K);
- if (apbcp_base == NULL) {
+ if (!apbcp_base) {
pr_err("error to ioremap APBC extension base\n");
return;
}

apbc_base = ioremap(apbc_phys, SZ_4K);
- if (apbc_base == NULL) {
+ if (!apbc_base) {
pr_err("error to ioremap APBC base\n");
return;
}
--
2.14.1

2017-09-27 09:27:14

by Sylwester Nawrocki

[permalink] [raw]
Subject: Re: [PATCH 3/3] clk/mmp: Adjust 12 checks for null pointers

On 09/27/2017 09:27 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Wed, 27 Sep 2017 09:00:21 +0200

> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit

Can you please fix your process and stop posting with above tags
in the commit message? These 3 tags are already in the header
of message you are sending. After your patches get applied
we end up with a mess in commit messages as below.

------------------------------8<-------------------------------
commit 0b08273c8ab7e688832120c4817b1adfdc56e231
Author: Markus Elfring <[email protected]>
Date: Thu Aug 17 21:35:16 2017 +0200

orangefs: Adjust three checks for null pointers

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
Signed-off-by: Mike Marshall <[email protected]>
------------------------------8<-------------------------------

Please see "DISCUSSION" paragraph of [1] for an explanation
of what should be put in the message body.

[1] https://git-scm.com/docs/git-format-patch

--
Thanks,
Sylwester

> The script “checkpatch.pl” pointed information out like the following.
>
> Comparison to NULL could be written !…
>
> Thus fix the affected source code places.
>
> Signed-off-by: Markus Elfring <[email protected]>

2017-11-14 02:02:44

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 3/3] clk/mmp: Adjust 12 checks for null pointers

On 09/27, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Wed, 27 Sep 2017 09:00:21 +0200
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The script “checkpatch.pl” pointed information out like the following.
>
> Comparison to NULL could be written !…
>
> Thus fix the affected source code places.
>
> 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

From 1579684493185597566@xxx Wed Sep 27 09:28:49 +0000 2017
X-GM-THRID: 1579676998363572579
X-Gmail-Labels: Inbox,Category Forums

2017-11-14 02:02:18

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 2/3] clk/mmp: Use common error handling code in mmp_clk_register_mix()

On 09/27, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Tue, 26 Sep 2017 22:33:18 +0200
>
> Add a jump target so that a bit of exception handling can be better reused
> at the end of this function.
>
> 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

From 1579676957053317993@xxx Wed Sep 27 07:29:02 +0000 2017
X-GM-THRID: 1579676957053317993
X-Gmail-Labels: Inbox,Category Forums

2017-11-14 02:02:40

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 1/3] clk/mmp: Delete an error message for a failed memory allocation in three functions

On 09/27, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Tue, 26 Sep 2017 22:25:38 +0200
>
> Omit extra messages for a memory allocation failure in these functions.
>
> 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

From 1579676763151234768@xxx Wed Sep 27 07:25:57 +0000 2017
X-GM-THRID: 1579676763151234768
X-Gmail-Labels: Inbox,Category Forums