lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 8 Mar 2019 22:18:52 +0100
From:   Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>
To:     Nick Desaulniers <ndesaulniers@...gle.com>
Cc:     Nathan Chancellor <natechancellor@...il.com>,
        Thierry Reding <thierry.reding@...il.com>,
        linux-pwm@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] pwm: img: Turn final 'else if' into 'else' in
 img_pwm_config

On Fri, Mar 08, 2019 at 10:38:11AM -0800, Nick Desaulniers wrote:
> On Fri, Mar 8, 2019 at 12:53 AM Uwe Kleine-König
> <u.kleine-koenig@...gutronix.de> wrote:
> >
> > On Thu, Mar 07, 2019 at 03:36:28PM -0700, Nathan Chancellor wrote:
> > > When building with -Wsometimes-uninitialized, Clang warns:
> > >
> > > drivers/pwm/pwm-img.c:126:13: error: variable 'timebase' is used
> > > uninitialized whenever 'if' condition is false
> > > [-Werror,-Wsometimes-uninitialized]
> > >
> > > The final else if functions as an else; make that explicit so that Clang
> > > understands that timebase cannot be used uninitialized.
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/400
> > > Signed-off-by: Nathan Chancellor <natechancellor@...il.com>
> > > ---
> > >  drivers/pwm/pwm-img.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
> > > index 815f5333bb8f..1cc5fbe1e1d3 100644
> > > --- a/drivers/pwm/pwm-img.c
> > > +++ b/drivers/pwm/pwm-img.c
> > > @@ -123,7 +123,7 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> > >       } else if (mul <= max_timebase * 512) {
> > >               div = PWM_CTRL_CFG_SUB_DIV0_DIV1;
> > >               timebase = DIV_ROUND_UP(mul, 512);
> > > -     } else if (mul > max_timebase * 512) {
> > > +     } else {
> > >               dev_err(chip->dev,
> > >                       "failed to configure timebase steps/divider value\n");
> > >               return -EINVAL;
> >
> > This can even be simplified further.
> >
> > From the probe function we have:
> >
> >         pwm_chip->max_period_ns = NSEC_PER_SEC * 512 * max_timebase / input_clk_hz
> 
> I had trouble verifying `input_clk_hz` in the above.  The divisor is
> `clk_get_rate(pwm->pwm_clk)`, but is it guaranteed to always be
> `input_clk_hz`? If so, where?

In the probe function it's called "clk_rate". We have:

	clk_rate = clk_get_rate(pwm->pwm_clk);
	...
	val = (u64)NSEC_PER_SEC * 512 * pwm->data->max_timebase;
	do_div(val, clk_rate);
	pwm->max_period_ns = val;

and in img_pwm_config we have:

	input_clk_hz = clk_get_rate(pwm_chip->pwm_clk);

I used the name used in img_pwm_config with the intention that my
reasoning is easier to understand, but obviously I failed.

This by the way highlights another patch opportunity: Unify the names
that the same thing gets the same name in the different functions. This
doesn't only affect "clk_rate" vs "input_clk_hz", but also "pwm_chip"
vs. "pwm".

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ