Re: [PATCH 2/2] clk/vt8500: Fix compilation warnings

From: Roman Volkov
Date: Tue May 31 2016 - 14:41:20 EST


Ð Tue, 31 May 2016 12:51:55 +0200
Arnd Bergmann <arnd@xxxxxxxx> ÐÐÑÐÑ:

> On Tuesday, May 24, 2016 11:07:53 PM CEST Roman Volkov wrote:
> > From: Roman Volkov <rvolkov@xxxxxxxxx>
> >
> > GCC 5.3.0 still throws the following warnings for functions
> > wm8750_find_pll_bits() and wm8850_find_pll_bits():
> >
> > warning: 'best_div2' may be used uninitialized in this function
> > warning: 'best_div1' may be used uninitialized in this function
> > warning: 'best_mul' may be used uninitialized in this function
> >
> > These warnings are false positives, the variables are controlled
> > by checking the value of the variable 'best_err' which is -1 by
> > default. It is safe to initialize all these variables to zero.
> >
> > Fixes: 090341b0a95d ("clk: vt8500: fix sign of possible PLL values")
> > Signed-off-by: Roman Volkov <rvolkov@xxxxxxxxx>
>
> With gcc-5.3 and linux-4.7-rc1, they should be gone now (no longer
> warning about this with gcov enabled), but I still get them with
> gcc-4.9.
>
> > diff --git a/drivers/clk/clk-vt8500.c b/drivers/clk/clk-vt8500.c
> > index 77650f19a9b6..7c970d7c0a6a 100644
> > --- a/drivers/clk/clk-vt8500.c
> > +++ b/drivers/clk/clk-vt8500.c
> > @@ -461,7 +461,7 @@ static int wm8750_find_pll_bits(unsigned long
> > rate, unsigned long parent_rate, {
> > u32 mul;
> > int div1, div2;
> > - u32 best_mul, best_div1, best_div2;
> > + u32 best_mul = 0, best_div1 = 0, best_div2 = 0;
> > unsigned long tclk, rate_err, best_err;
> >
> > best_err = (unsigned long)-1;
> > @@ -513,7 +513,7 @@ static int wm8850_find_pll_bits(unsigned long
> > rate, unsigned long parent_rate, {
> > u32 mul;
> > int div1, div2;
> > - u32 best_mul, best_div1, best_div2;
> > + u32 best_mul = 0, best_div1 = 0, best_div2 = 0;
> > unsigned long tclk, rate_err, best_err;
> >
> > best_err = (unsigned long)-1;
> >
>
> I see you only patch two instances but not the third one. I think
> we should do it consistently at least.
>
> Coincidentally, I've just done another patch for this myself, since
> it's the last gcc-4.9 warning we get in linux-4.7.
>
> My version below
>
> commit a38daeb34a2dc9d39ee1f153244cfcd83e865e0d
> Author: Arnd Bergmann <arnd@xxxxxxxx>
> Date: Tue May 31 10:41:26 2016 +0200
>
> clk: vt8500: fix gcc-4.9 warnings
>
> This fixes some false positive warnings we get with older compiler
> versions:
>
> clk-vt8500.c: In function âwm8650_find_pll_bitsâ:
> clk-vt8500.c:430:12: âbest_div2â may be used uninitialized in this
> function clk-vt8500.c:429:12: âbest_div1â may be used uninitialized
> in this function clk-vt8500.c:428:14: âbest_mulâ may be used
> uninitialized in this function clk-vt8500.c: In function
> âwm8750_find_pll_bitsâ: clk-vt8500.c:509:12: âbest_div2â may be used
> uninitialized in this function clk-vt8500.c:508:12: âbest_div1â may
> be used uninitialized in this function clk-vt8500.c:507:14:
> âbest_mulâ may be used uninitialized in this function clk-vt8500.c:
> In function âwm8850_find_pll_bitsâ: clk-vt8500.c:560:12: âbest_div2â
> may be used uninitialized in this function clk-vt8500.c:559:12:
> âbest_div1â may be used uninitialized in this function
> clk-vt8500.c:558:14: âbest_mulâ may be used uninitialized in this
> function
>
> As the local variables are only use for temporaries, we can just
> as well assign the final values directly, which also makes the
> code slightly shorter.
>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
>
> diff --git a/drivers/clk/clk-vt8500.c b/drivers/clk/clk-vt8500.c
> index b0f76a84f1e9..d5a3453970d0 100644
> --- a/drivers/clk/clk-vt8500.c
> +++ b/drivers/clk/clk-vt8500.c
> @@ -388,7 +388,6 @@ static int wm8650_find_pll_bits(unsigned long
> rate, unsigned long parent_rate, {
> u32 mul, div1;
> int div2;
> - u32 best_mul, best_div1, best_div2;
> unsigned long tclk, rate_err, best_err;
>
> best_err = (unsigned long)-1;
> @@ -411,9 +410,9 @@ static int wm8650_find_pll_bits(unsigned long
> rate, unsigned long parent_rate,
> if (rate_err < best_err) {
> best_err = rate_err;
> - best_mul = mul;
> - best_div1 = div1;
> - best_div2 = div2;
> + *multiplier = mul;
> + *divisor1 = div1;
> + *divisor2 = div2;
> }
> }
>
> @@ -425,10 +424,6 @@ static int wm8650_find_pll_bits(unsigned long
> rate, unsigned long parent_rate, /* if we got here, it wasn't an
> exact match */ pr_warn("%s: requested rate %lu, found rate %lu\n",
> __func__, rate, rate - best_err);
> - *multiplier = best_mul;
> - *divisor1 = best_div1;
> - *divisor2 = best_div2;
> -
> return 0;
> }
>
> @@ -464,7 +459,6 @@ static int wm8750_find_pll_bits(unsigned long
> rate, unsigned long parent_rate, {
> u32 mul;
> int div1, div2;
> - u32 best_mul, best_div1, best_div2;
> unsigned long tclk, rate_err, best_err;
>
> best_err = (unsigned long)-1;
> @@ -488,9 +482,9 @@ static int wm8750_find_pll_bits(unsigned long
> rate, unsigned long parent_rate,
> if (rate_err < best_err) {
> best_err = rate_err;
> - best_mul = mul;
> - best_div1 = div1;
> - best_div2 = div2;
> + *multiplier = mul;
> + *divisor1 = div1;
> + *divisor2 = div2;
> }
> }
>
> @@ -503,10 +497,7 @@ static int wm8750_find_pll_bits(unsigned long
> rate, unsigned long parent_rate, pr_warn("%s: requested rate %lu,
> found rate %lu\n", __func__, rate, rate - best_err);
>
> - *filter = wm8750_get_filter(parent_rate, best_div1);
> - *multiplier = best_mul;
> - *divisor1 = best_div1;
> - *divisor2 = best_div2;
> + *filter = wm8750_get_filter(parent_rate, *divisor1);
>
> return 0;
> }
> @@ -516,7 +507,6 @@ static int wm8850_find_pll_bits(unsigned long
> rate, unsigned long parent_rate, {
> u32 mul;
> int div1, div2;
> - u32 best_mul, best_div1, best_div2;
> unsigned long tclk, rate_err, best_err;
>
> best_err = (unsigned long)-1;
> @@ -540,9 +530,9 @@ static int wm8850_find_pll_bits(unsigned long
> rate, unsigned long parent_rate,
> if (rate_err < best_err) {
> best_err = rate_err;
> - best_mul = mul;
> - best_div1 = div1;
> - best_div2 = div2;
> + *multiplier = mul;
> + *divisor1 = div1;
> + *divisor2 = div2;
> }
> }
>
> @@ -555,10 +545,6 @@ static int wm8850_find_pll_bits(unsigned long
> rate, unsigned long parent_rate, pr_warn("%s: requested rate %lu,
> found rate %lu\n", __func__, rate, rate - best_err);
>
> - *multiplier = best_mul;
> - *divisor1 = best_div1;
> - *divisor2 = best_div2;
> -
> return 0;
> }
>
>
>

Arnd, your version is fine for me. We may apply it instead.

As you can see, I attached another patch where the logic for WM8650 is
completely reworked. This patch also removes the warning, that is why
fixing the wm8650 function is not necessary.

What about the WM8650 enhancement? Can I apply it on top of your
changes?

Regards,
Roman