2016-10-24 20:43:33

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 0/3] clk: keystone: Fix some error handling paths

The first of these 3 patches is a v2 of a patch posted earlier.
The main change in this v2 is the propagation of the error returned by
'clk_register_pll()'.

The 2nd one is completely un-related and fixes some typo in error messages
spoted while looking at the file.

Finaly, the 3rd one refactors the '_of_pll_clk_init' function in order to
factorize some cleanups in case of error and to add some missing 'iounmap()'
calls if 'clk_register_pll()' fails.

These patches are un-compiled. I get some errors for some reasons in my build
environment. I've not checked further the root cause of these build errors
but I guess that my plateform is not what is expected to build this code.

Christophe JAILLET (3):
clk: keystone: Fix an error checking
clk: keystone: Fix some error messages
clk: keystone: Fix missing iounmap calls in an error handling path

drivers/clk/keystone/pll.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

--
2.9.3


2016-10-24 20:43:46

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 2/3] clk: keystone: Fix some error messages

Report 'bit-shift' in the error message as it is the property we are
looking for.

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

diff --git a/drivers/clk/keystone/pll.c b/drivers/clk/keystone/pll.c
index 70d6fb2d23bc..35c0e2b011d1 100644
--- a/drivers/clk/keystone/pll.c
+++ b/drivers/clk/keystone/pll.c
@@ -271,7 +271,7 @@ static void __init of_pll_div_clk_init(struct device_node *node)
}

if (of_property_read_u32(node, "bit-shift", &shift)) {
- pr_err("%s: missing 'shift' property\n", __func__);
+ pr_err("%s: missing 'bit-shift' property\n", __func__);
return;
}

@@ -315,7 +315,7 @@ static void __init of_pll_mux_clk_init(struct device_node *node)
}

if (of_property_read_u32(node, "bit-shift", &shift)) {
- pr_err("%s: missing 'shift' property\n", __func__);
+ pr_err("%s: missing 'bit-shift' property\n", __func__);
return;
}

--
2.9.3

2016-10-24 20:43:52

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path

Factorize 'iounmap()' calls in the error handling path.
The main goal is to add these calls if 'clk_register_pll()' fails.

Add an error message if an 'of_iomap' call fails to be consistent.

Signed-off-by: Christophe JAILLET <[email protected]>
---
Un-compiled & un-tested
---
drivers/clk/keystone/pll.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/keystone/pll.c b/drivers/clk/keystone/pll.c
index 35c0e2b011d1..73a2558b29c0 100644
--- a/drivers/clk/keystone/pll.c
+++ b/drivers/clk/keystone/pll.c
@@ -191,7 +191,6 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
pll_data->pll_ctl0 = of_iomap(node, i);
if (!pll_data->pll_ctl0) {
pr_err("%s: ioremap failed\n", __func__);
- iounmap(pll_data->pllod);
goto out;
}

@@ -206,8 +205,7 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
i = of_property_match_string(node, "reg-names", "multiplier");
pll_data->pllm = of_iomap(node, i);
if (!pll_data->pllm) {
- iounmap(pll_data->pll_ctl0);
- iounmap(pll_data->pllod);
+ pr_err("%s: ioremap failed\n", __func__);
goto out;
}
}
@@ -220,6 +218,12 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)

out:
pr_err("%s: error initializing pll %s\n", __func__, node->name);
+ if (pll_data->pllm)
+ iounmap(pll_data->pllm);
+ if (pll_data->pll_ctl0)
+ iounmap(pll_data->pll_ctl0);
+ if (pll_data->pllod)
+ iounmap(pll_data->pllod);
kfree(pll_data);
}

--
2.9.3

2016-10-24 20:43:54

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH 1/3] clk: keystone: Fix an error checking

clk_register_pll() can return ERR_PTR(-ENOMEM) so checking the return value
against NULL only is not correct.
In order to fix it, update clk_register_pll() to always return an error
pointer in case of error and check the return value with IS_ERR.

While at it, also fix a tab vs space in the surrounding code.

Signed-off-by: Christophe JAILLET <[email protected]>
---
Un-compiled and un-tested.
---
drivers/clk/keystone/pll.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/keystone/pll.c b/drivers/clk/keystone/pll.c
index a26ba2184454..70d6fb2d23bc 100644
--- a/drivers/clk/keystone/pll.c
+++ b/drivers/clk/keystone/pll.c
@@ -140,7 +140,7 @@ static struct clk *clk_register_pll(struct device *dev,
init.parent_names = (parent_name ? &parent_name : NULL);
init.num_parents = (parent_name ? 1 : 0);

- pll->pll_data = pll_data;
+ pll->pll_data = pll_data;
pll->hw.init = &init;

clk = clk_register(NULL, &pll->hw);
@@ -150,7 +150,7 @@ static struct clk *clk_register_pll(struct device *dev,
return clk;
out:
kfree(pll);
- return NULL;
+ return clk;
}

/**
@@ -213,7 +213,7 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
}

clk = clk_register_pll(NULL, node->name, parent_name, pll_data);
- if (clk) {
+ if (!IS_ERR(clk)) {
of_clk_add_provider(node, of_clk_src_simple_get, clk);
return;
}
--
2.9.3

2016-10-25 07:08:18

by walter harms

[permalink] [raw]
Subject: Re: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path



Am 24.10.2016 22:43, schrieb Christophe JAILLET:
> Factorize 'iounmap()' calls in the error handling path.
> The main goal is to add these calls if 'clk_register_pll()' fails.
>
> Add an error message if an 'of_iomap' call fails to be consistent.
>
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---
> Un-compiled & un-tested
> ---
> drivers/clk/keystone/pll.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/keystone/pll.c b/drivers/clk/keystone/pll.c
> index 35c0e2b011d1..73a2558b29c0 100644
> --- a/drivers/clk/keystone/pll.c
> +++ b/drivers/clk/keystone/pll.c
> @@ -191,7 +191,6 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
> pll_data->pll_ctl0 = of_iomap(node, i);
> if (!pll_data->pll_ctl0) {
> pr_err("%s: ioremap failed\n", __func__);
> - iounmap(pll_data->pllod);
> goto out;
> }
>
> @@ -206,8 +205,7 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
> i = of_property_match_string(node, "reg-names", "multiplier");
> pll_data->pllm = of_iomap(node, i);
> if (!pll_data->pllm) {
> - iounmap(pll_data->pll_ctl0);
> - iounmap(pll_data->pllod);
> + pr_err("%s: ioremap failed\n", __func__);
> goto out;
> }
> }
> @@ -220,6 +218,12 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
>
> out:
> pr_err("%s: error initializing pll %s\n", __func__, node->name);
> + if (pll_data->pllm)
> + iounmap(pll_data->pllm);
> + if (pll_data->pll_ctl0)
> + iounmap(pll_data->pll_ctl0);
> + if (pll_data->pllod)
> + iounmap(pll_data->pllod);
> kfree(pll_data);
> }
>

IMHO calles the iounmap() need no check for NULL.

re,
wh

2016-10-25 20:35:29

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path

On 10/25, walter harms wrote:
> Am 24.10.2016 22:43, schrieb Christophe JAILLET:
> > @@ -220,6 +218,12 @@ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl)
> >
> > out:
> > pr_err("%s: error initializing pll %s\n", __func__, node->name);
> > + if (pll_data->pllm)
> > + iounmap(pll_data->pllm);
> > + if (pll_data->pll_ctl0)
> > + iounmap(pll_data->pll_ctl0);
> > + if (pll_data->pllod)
> > + iounmap(pll_data->pllod);
> > kfree(pll_data);
> > }
> >
>
> IMHO calles the iounmap() need no check for NULL.
>

ARM doesn't seem to check for NULL there though. So that would be
a bug.

It would be nice to remove the checks though. Perhaps someone
could do that by unifying ionumap into asm-generic with the NULL
check and then have architecture specific functions for the rest
of it?

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

2016-11-02 00:22:32

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 1/3] clk: keystone: Fix an error checking

On 10/24, Christophe JAILLET wrote:
> clk_register_pll() can return ERR_PTR(-ENOMEM) so checking the return value
> against NULL only is not correct.

The code just doesn't propagate the error up to the caller.
Instead the caller treats NULL as an error and non-NULL as valid.
If the callee detects an error it hides it and returns NULL.

> In order to fix it, update clk_register_pll() to always return an error
> pointer in case of error and check the return value with IS_ERR.
>
> While at it, also fix a tab vs space in the surrounding code.
>
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---
> Un-compiled and un-tested.

Please at least compile test patches.

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

2016-11-04 05:44:10

by Christophe JAILLET

[permalink] [raw]
Subject: Re: [PATCH 1/3] clk: keystone: Fix an error checking

Le 02/11/2016 ? 01:22, Stephen Boyd a ?crit :
> On 10/24, Christophe JAILLET wrote:
>> clk_register_pll() can return ERR_PTR(-ENOMEM) so checking the return value
>> against NULL only is not correct.
> The code just doesn't propagate the error up to the caller.
> Instead the caller treats NULL as an error and non-NULL as valid.
> If the callee detects an error it hides it and returns NULL.

Could you please clarify?
I thought that your point was that 'clk_register_pll()' was returning
NULL when 'clk_register()' was returning an error.
The proposed patch fixes it and now 'clk_register_pll()' returns:
- either ERR_PTR(-ENOMEM) if zkalloc fails
- or clk if 'clk_register()' fails. In this case it is an error pointer
- or a valid, non NULL, pointer in case of success

The caller, '_of_pll_clk_init()' has also been updated to test the
return value using IS_ERR.


So, which caller/callee do you refer to?
Would you like '_of_pll_clk_init()' to also propagate the error?

Or is it the phrasing of the log entry which is not clear enough and
should be updated?

>
>> In order to fix it, update clk_register_pll() to always return an error
>> pointer in case of error and check the return value with IS_ERR.
>>
>> While at it, also fix a tab vs space in the surrounding code.
>>
>> Signed-off-by: Christophe JAILLET <[email protected]>
>> ---
>> Un-compiled and un-tested.
> Please at least compile test patches.
Agreed, and I usually do.
But in this particular case, I don't have the build environment to do it.

I preferred to report what looks like a (small) bug to me and clearly
state that I didn't even compile-tested it rather than just ignoring it.
Hoping that this approach, in such a case, is acceptable.

CJ