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, 20 Dec 2019 11:32:42 +0200
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Dan Robertson <dan@...obertson.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        linux-iio <linux-iio@...r.kernel.org>,
        Peter Meerwald-Stadler <pmeerw@...erw.net>,
        devicetree <devicetree@...r.kernel.org>,
        Hartmut Knaack <knaack.h@....de>,
        Rob Herring <robh+dt@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Randy Dunlap <rdunlap@...radead.org>,
        Joe Perches <joe@...ches.com>,
        Linus Walleij <linus.walleij@...aro.org>
Subject: Re: [PATCH v7 2/3] iio: (bma400) add driver for the BMA400

On Fri, Dec 20, 2019 at 11:27 AM Andy Shevchenko
<andy.shevchenko@...il.com> wrote:
> On Fri, Dec 20, 2019 at 6:48 AM Dan Robertson <dan@...obertson.com> wrote:
> > On Thu, Dec 19, 2019 at 01:02:28PM +0200, Andy Shevchenko wrote:
> > > On Thu, Dec 19, 2019 at 6:27 AM Dan Robertson <dan@...obertson.com> wrote:
>
> > > > +static int bma400_set_accel_output_data_rate(struct bma400_data *data,
> > > > +                                            int hz, int uhz)
> > > > +{
> > > > +       unsigned int idx;
> > > > +       unsigned int odr;
> > > > +       unsigned int val;
> > > > +       int ret;
> > > > +
> > > > +       if (hz >= BMA400_ACC_ODR_MIN_WHOLE_HZ) {
> > > > +               if (uhz || hz % BMA400_ACC_ODR_MIN_WHOLE_HZ)
> > > > +                       return -EINVAL;
> > > > +
> > > > +               val = hz / BMA400_ACC_ODR_MIN_WHOLE_HZ;
> > >
> > > Again, AFAICS division may be avoided in both cases (% and / above)
> > > because of is_power_of_2() check below.
> > > Can you revisit this?
> >
> > Yeah I can update this in the next patchset, but I don't know if it is much more
> > readable this way.
>
> You may describe the algo in the comment.
>
> Let's see how it might look like
>
>   if (uhz)
>     return -EINVAL;
>   idx = __ffs(val);
>   /* We're expecting value to be 2^n * ODR_MIN_WHOLE_HZ */
>   if ((val >> idx) != BMA400_ACC_ODR_MIN_WHOLE_HZ)

Okay, this would require trickier conditional for the cases when
MIN_WHOLE_HZ can be divided by 2^k...
Still from performance point of view it might be much faster than division.

>     retutn -EINVAL;
>   idx += BMA400_ACC_ODR_MIN_RAW + 1;
>
> Would it work?
>
> > > > +               if (!is_power_of_2(val))
> > > > +                       return -EINVAL;
> > > > +
> > > > +               idx = __ffs(val) + BMA400_ACC_ODR_MIN_RAW + 1;

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ