* [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
@ 2023-06-22 15:56 Nathan Chancellor
2023-06-22 16:36 ` Nick Desaulniers
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Nathan Chancellor @ 2023-06-22 15:56 UTC (permalink / raw)
To: tsbogend
Cc: sergio.paracuellos, sboyd, nathan, ndesaulniers, trix, linux-clk,
linux-mips, patches, llvm
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;
| ^
| = 0
2 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.
Fixes: 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")
Closes: https://github.com/ClangBuiltLinux/linux/issues/1879
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
drivers/clk/ralink/clk-mtmips.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/ralink/clk-mtmips.c b/drivers/clk/ralink/clk-mtmips.c
index 9322c6210a33..1e7991439527 100644
--- a/drivers/clk/ralink/clk-mtmips.c
+++ b/drivers/clk/ralink/clk-mtmips.c
@@ -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,
--
Nathan Chancellor <nathan@kernel.org>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
2023-06-22 15:56 [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks() Nathan Chancellor
@ 2023-06-22 16:36 ` Nick Desaulniers
2023-06-23 6:12 ` Dan Carpenter
2023-06-22 16:53 ` Sergio Paracuellos
2023-06-23 13:09 ` Thomas Bogendoerfer
2 siblings, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2023-06-22 16:36 UTC (permalink / raw)
To: Nathan Chancellor
Cc: tsbogend, sergio.paracuellos, sboyd, trix, linux-clk, linux-mips,
patches, llvm
On Thu, Jun 22, 2023 at 8:56 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> 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;
> | ^
> | = 0
> 2 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.
>
> Fixes: 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1879
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
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.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> drivers/clk/ralink/clk-mtmips.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/ralink/clk-mtmips.c b/drivers/clk/ralink/clk-mtmips.c
> index 9322c6210a33..1e7991439527 100644
> --- a/drivers/clk/ralink/clk-mtmips.c
> +++ b/drivers/clk/ralink/clk-mtmips.c
> @@ -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,
> --
> Nathan Chancellor <nathan@kernel.org>
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
2023-06-22 15:56 [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks() Nathan Chancellor
2023-06-22 16:36 ` Nick Desaulniers
@ 2023-06-22 16:53 ` Sergio Paracuellos
2023-06-23 13:09 ` Thomas Bogendoerfer
2 siblings, 0 replies; 5+ messages in thread
From: Sergio Paracuellos @ 2023-06-22 16:53 UTC (permalink / raw)
To: Nathan Chancellor
Cc: tsbogend, sboyd, ndesaulniers, trix, linux-clk, linux-mips,
patches, llvm
On Thu, Jun 22, 2023 at 5:56 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> 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;
> | ^
> | = 0
> 2 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.
>
> Fixes: 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1879
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> drivers/clk/ralink/clk-mtmips.c | 2 ++
> 1 file changed, 2 insertions(+)
Thanks for the patch, Nathan!!
Acked-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Best regards,
Sergio Paracuellos
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
2023-06-22 16:36 ` Nick Desaulniers
@ 2023-06-23 6:12 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-06-23 6:12 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Nathan Chancellor, tsbogend, sergio.paracuellos, sboyd, trix,
linux-clk, linux-mips, patches, llvm
On Thu, Jun 22, 2023 at 09:36:53AM -0700, Nick Desaulniers wrote:
> On Thu, Jun 22, 2023 at 8:56 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > 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;
> > | ^
> > | = 0
> > 2 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.
> >
> > Fixes: 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")
> > Closes: https://github.com/ClangBuiltLinux/linux/issues/1879
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
>
> 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...]
>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()
2023-06-22 15:56 [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks() Nathan Chancellor
2023-06-22 16:36 ` Nick Desaulniers
2023-06-22 16:53 ` Sergio Paracuellos
@ 2023-06-23 13:09 ` Thomas Bogendoerfer
2 siblings, 0 replies; 5+ messages in thread
From: Thomas Bogendoerfer @ 2023-06-23 13:09 UTC (permalink / raw)
To: Nathan Chancellor
Cc: sergio.paracuellos, sboyd, ndesaulniers, trix, linux-clk,
linux-mips, patches, llvm
On Thu, Jun 22, 2023 at 03:56:19PM +0000, Nathan Chancellor wrote:
> 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;
> | ^
> | = 0
> 2 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.
>
> Fixes: 6f3b15586eef ("clk: ralink: add clock and reset driver for MTMIPS SoCs")
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1879
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> drivers/clk/ralink/clk-mtmips.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/ralink/clk-mtmips.c b/drivers/clk/ralink/clk-mtmips.c
> index 9322c6210a33..1e7991439527 100644
> --- a/drivers/clk/ralink/clk-mtmips.c
> +++ b/drivers/clk/ralink/clk-mtmips.c
> @@ -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
applied to mips-next.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-23 13:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-22 15:56 [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks() Nathan Chancellor
2023-06-22 16:36 ` Nick Desaulniers
2023-06-23 6:12 ` Dan Carpenter
2023-06-22 16:53 ` Sergio Paracuellos
2023-06-23 13:09 ` Thomas Bogendoerfer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).