clk: keystone: Fix some error handling paths
cover 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(-)
Signature · 1 line
2.9.3
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.
---
Un-compiled and un-tested.
--- drivers/clk/keystone/pll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/keystone/pll.c +3 -3
@@ -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 ; }
Signature · 1 line
2.9.3
Re: [PATCH 1/3] clk: keystone: Fix an error checking
Quoted 2 lines · Christophe JAILLET
clk_register_pll()can returnERR_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.
Quoted 8 lines
In order to fix it, update
clk_register_pll()to always return an error pointer in case of error and check the return value withIS_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.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 1/3] clk: keystone: Fix an error checking
Quoted 6 lines · Stephen Boyd
Quoted 2 lines · Christophe JAILLET
clk_register_pll()can returnERR_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?
Quoted 10 lines
Quoted 9 lines
In order to fix it, update
clk_register_pll()to always return an error pointer in case of error and check the return value withIS_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
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/3 clk: keystone: Fix some error messages
In reply to Christophe JAILLETReport 'bit-shift' in the error message as it is the property we are looking for.
--- drivers/clk/keystone/pll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/keystone/pll.c +2 -2
@@ -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 ; }
Signature · 1 line
2.9.3
PATCH 3/3 clk: keystone: Fix missing iounmap calls in an error handling path
In reply to Christophe JAILLETFactorize '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.
---
Un-compiled & un-tested
--- drivers/clk/keystone/pll.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/clk/keystone/pll.c +7 -3
@@ -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); }
Signature · 1 line
2.9.3
Re: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path
Am 24.10.2016 22:43, schrieb Christophe JAILLET:
Quoted 37 lines
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(-)drivers/clk/keystone/pll.c +1
-3@@ -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:
drivers/clk/keystone/pll.c static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl) · line 229
Quoted 10 lines
drivers/clk/keystone/pll.c +6
-0pr_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
Re: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path
Quoted 17 lines · walter harms
Am 24.10.2016 22:43, schrieb Christophe JAILLET:
drivers/clk/keystone/pll.c static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl) · line 229
Quoted 13 lines
drivers/clk/keystone/pll.c +6
-0@@ -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?
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path
In reply to Christophe JAILLETAm 25.10.2016 22:35, schrieb Stephen Boyd:
Quoted 19 lines · walter harms
Quoted 17 lines
Am 24.10.2016 22:43, schrieb Christophe JAILLET:
drivers/clk/keystone/pll.c static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl) · line 229
Quoted 13 lines
drivers/clk/keystone/pll.c +6
-0@@ -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.
Quoted 8 lines
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?
Is there a specific reason not to check ?
It seems not wise to have different behavior across architectures.
re,
wh
Re: [PATCH 3/3] clk: keystone: Fix missing iounmap calls in an error handling path
In reply to Christophe JAILLETQuoted 25 lines · walter harms
Am 25.10.2016 22:35, schrieb Stephen Boyd:
Quoted 22 lines · walter harms
Quoted 17 lines
Am 24.10.2016 22:43, schrieb Christophe JAILLET:
drivers/clk/keystone/pll.c static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl) · line 229
Quoted 13 lines
drivers/clk/keystone/pll.c +6
-0@@ -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.
Quoted 9 lines
Quoted 5 lines
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?
Is there a specific reason not to check ?
It seems not wise to have different behavior across architectures.
I have no idea. Patches welcome.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project