lkml.org 
[lkml]   [2019]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v7 2/3] iio: (bma400) add driver for the BMA400
On Fri, Dec 20, 2019 at 11:32:42AM +0200, Andy Shevchenko wrote:
> On Fri, Dec 20, 2019 at 11:27 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Fri, Dec 20, 2019 at 6:48 AM Dan Robertson <dan@dlrobertson.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@dlrobertson.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.

I think the other checks will ensure we return -EINVAL in those cases. I ran a
basic for loop and verified this.

Cheers,

- Dan

\
 
 \ /
  Last update: 2019-12-20 16:44    [W:0.038 / U:3.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site