Re: [PATCH] clk: ralink: mtmips: Fix uninitialized use of ret in mtmips_register_{fixed,factor}_clocks()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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@xxxxxxxxxx>
> 
> 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




[Index of Archives]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux