clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
Subsystems (3)
PATCH 1/1 clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
Clang warns:
drivers/clk/ralink/clk-mtmips.c:309:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]
309 | return ret;
| ^~~
drivers/clk/ralink/clk-mtmips.c:285:9: note: initialize the variable 'ret' to silence this warning
285 | int ret, i;
| ^
| = 0
drivers/clk/ralink/clk-mtmips.c:359:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]
359 | return ret;
| ^~~
drivers/clk/ralink/clk-mtmips.c:335:9: note: initialize the variable 'ret' to silence this warning
335 | int ret, i;
| ^
| = 02 errors generated.
Set ret to the return value of clk_hw_register_fixed_rate() using the PTR_ERR() macro, which ensures ret is not used uninitialized, clearing up the warning.
--- drivers/clk/ralink/clk-mtmips.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/ralink/clk-mtmips.c +2 -0
@@ -292,6 +292,7 @@ static int mtmips_register_fixed_clocks(struct clk_hw_onecell_data *clk_data, sclk->parent,0 , sclk->rate);if (IS_ERR (sclk->hw)) { + ret =PTR_ERR (sclk->hw);pr_err ("Couldn't register fixed clock %d\n" , idx); goto err_clk_unreg; }
@@ -342,6 +343,7 @@ static int mtmips_register_factor_clocks(struct clk_hw_onecell_data *clk_data, sclk->parent, sclk->flags, sclk->mult, sclk->div);if (IS_ERR (sclk->hw)) { + ret =PTR_ERR (sclk->hw);pr_err ("Couldn't register factor clock %d\n" , idx); goto err_clk_unreg; }
---
base-commit: fd99ac5055d4705e91c73d1adba18bc71c8511a8
change-id: 20230622-mips-ralink-clk-wuninitialized-150bd0336187
Best regards,
Signature · 1 line
Nathan Chancellor <[email protected]>
Quoted 19 lines · Nathan Chancellor
Clang warns:
drivers/clk/ralink/clk-mtmips.c:309:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]309 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:285:9: note: initialize the variable 'ret' to silence this warning 285 | int ret, i; | ^ | = 0 drivers/clk/ralink/clk-mtmips.c:359:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized] 359 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:335:9: note: initialize the variable 'ret' to silence this warning 335 | int ret, i; | ^ | = 02 errors generated.
Quoted 7 lines
Set ret to the return value of
clk_hw_register_fixed_rate()using thePTR_ERR()macro, which ensures ret is not used uninitialized, clearing up the warning.Fixes 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")Signed-off-by Nathan Chancellor <[email protected]>
Thanks for the patch!PTR_ERR returns a long; assigning to an int risks truncation of the error. The use of PTR_ERR on L1079 has a similar risk...]
Maybe Sergio wants to revisit that in more detail, but this at least fixes the build for us.
Quoted 33 lines
--- drivers/clk/ralink/clk-mtmips.c | 2 ++ 1 file changed, 2 insertions(+)drivers/clk/ralink/clk-mtmips.c +2
-1@@ -292,6 +292,7 @@ static int mtmips_register_fixed_clocks(struct clk_hw_onecell_data *clk_data, sclk->parent,0 , sclk->rate);if (IS_ERR (sclk->hw)) { + ret =PTR_ERR (sclk->hw);pr_err ("Couldn't register fixed clock %d\n" , idx); goto err_clk_unreg; }@@ -342,6 +343,7 @@ static int mtmips_register_factor_clocks(struct clk_hw_onecell_data *clk_data, sclk->parent, sclk->flags, sclk->mult, sclk->div);if (IS_ERR (sclk->hw)) { + ret =PTR_ERR (sclk->hw);pr_err ("Couldn't register factor clock %d\n" , idx); goto err_clk_unreg; } ---base-commit:
fd99ac5055d4705e91c73d1adba18bc71c8511a8
change-id: 20230622-mips-ralink-clk-wuninitialized-150bd0336187Best regards,
--
Nathan Chancellor <[email protected]>
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 24 lines · Nick Desaulniers
Quoted 23 lines · Nathan Chancellor
Clang warns:
drivers/clk/ralink/clk-mtmips.c:309:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]309 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:285:9: note: initialize the variable 'ret' to silence this warning 285 | int ret, i; | ^ | = 0 drivers/clk/ralink/clk-mtmips.c:359:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized] 359 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:335:9: note: initialize the variable 'ret' to silence this warning 335 | int ret, i; | ^ | = 02 errors generated.
Set ret to the return value of
clk_hw_register_fixed_rate()using thePTR_ERR()macro, which ensures ret is not used uninitialized, clearing up the warning.
Quoted 8 lines
Quoted 3 lines
Fixes 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")Signed-off-by Nathan Chancellor <[email protected]>Thanks for the patch!
PTR_ERRreturns a long; assigning to an int risks truncation of the error. The use ofPTR_ERRon L1079 has a similar risk...]
If PTR_ERR() ever returns anything outside of the (-4095)-(0) range then we are already screwed.
I'm 90% sure there is a reason why PTR_ERR() returns long but I can't think off the top of my head why that is... It's been that way since before the git era. I could imagine type promotion bugs involving u32 and int if we changed it.
ssize_t ret_val = PTR_ERR(x) ?: u32_something;
Or maybe Linus just felt casting a pointer to int was ugly.
regards,
dan carpenter
Quoted 23 lines · Nathan Chancellor
Clang warns:
drivers/clk/ralink/clk-mtmips.c:309:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]309 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:285:9: note: initialize the variable 'ret' to silence this warning 285 | int ret, i; | ^ | = 0 drivers/clk/ralink/clk-mtmips.c:359:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized] 359 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:335:9: note: initialize the variable 'ret' to silence this warning 335 | int ret, i; | ^ | = 02 errors generated.
Set ret to the return value of
clk_hw_register_fixed_rate()using thePTR_ERR()macro, which ensures ret is not used uninitialized, clearing up the warning.
Quoted 6 lines
Fixes 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")Signed-off-by Nathan Chancellor <[email protected]>--- drivers/clk/ralink/clk-mtmips.c | 2 ++ 1 file changed, 2 insertions(+)
Thanks for the patch, Nathan!!
Best regards,
Sergio Paracuellos
Quoted 51 lines · Nathan Chancellor
Clang warns:
drivers/clk/ralink/clk-mtmips.c:309:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]309 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:285:9: note: initialize the variable 'ret' to silence this warning 285 | int ret, i; | ^ | = 0 drivers/clk/ralink/clk-mtmips.c:359:9: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized] 359 | return ret; | ^~~ drivers/clk/ralink/clk-mtmips.c:335:9: note: initialize the variable 'ret' to silence this warning 335 | int ret, i; | ^ | = 02 errors generated.
Set ret to the return value of
clk_hw_register_fixed_rate()using thePTR_ERR()macro, which ensures ret is not used uninitialized, clearing up the warning.Fixes 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")Signed-off-by Nathan Chancellor <[email protected]>--- drivers/clk/ralink/clk-mtmips.c | 2 ++ 1 file changed, 2 insertions(+)drivers/clk/ralink/clk-mtmips.c +2
-1@@ -292,6 +292,7 @@ static int mtmips_register_fixed_clocks(struct clk_hw_onecell_data *clk_data, sclk->parent,0 , sclk->rate);if (IS_ERR (sclk->hw)) { + ret =PTR_ERR (sclk->hw);pr_err ("Couldn't register fixed clock %d\n" , idx); goto err_clk_unreg; }@@ -342,6 +343,7 @@ static int mtmips_register_factor_clocks(struct clk_hw_onecell_data *clk_data, sclk->parent, sclk->flags, sclk->mult, sclk->div);if (IS_ERR (sclk->hw)) { + ret =PTR_ERR (sclk->hw);pr_err ("Couldn't register factor clock %d\n" , idx); goto err_clk_unreg; } ---
Quoted 2 lines
base-commit:
fd99ac5055d4705e91c73d1adba18bc71c8511a8
change-id: 20230622-mips-ralink-clk-wuninitialized-150bd0336187
applied to mips-next.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]