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] [day] [month] [year] [list]
Message-ID: <aFpjkwfxHq8EGFE5@smile.fi.intel.com>
Date: Tue, 24 Jun 2025 11:36:35 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Lothar Rubusch <l.rubusch@...il.com>
Cc: lars@...afoo.de, Michael.Hennerich@...log.com, jic23@...nel.org,
	dlechner@...libre.com, nuno.sa@...log.com, andy@...nel.org,
	corbet@....net, linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
	eraretuya@...il.com
Subject: Re: [PATCH v10 6/7] iio: accel: adxl345: extend inactivity time for
 less than 1s

On Tue, Jun 24, 2025 at 10:18:35AM +0200, Lothar Rubusch wrote:
> On Tue, Jun 24, 2025 at 9:38 AM Andy Shevchenko
> <andriy.shevchenko@...el.com> wrote:
> > On Mon, Jun 23, 2025 at 11:21:01PM +0200, Lothar Rubusch wrote:
> > > On Mon, Jun 23, 2025 at 12:17 PM Andy Shevchenko
> > > <andriy.shevchenko@...el.com> wrote:
> > > > On Sun, Jun 22, 2025 at 03:50:09PM +0000, Lothar Rubusch wrote:

...

> > > > > -     if (val == 0) {
> > > > > +     if (val_int == 0 && val_fract == 0) {
> > >
> > > The case for 0sec, 0.0 or setting "0" and fract will consequently be
> > > "0". 0 is an invalid input for this period and sensor, so it will
> > > default to an optimized period based on given ODR.
> > >
> > > > > +             /* Generated inactivity time based on ODR */
> > > > >               ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, &regval);
> > > > >               if (ret)
> > > > >                       return ret;
> > > >
> > > > >               odr = FIELD_GET(ADXL345_BW_RATE_MSK, regval);
> > > > >               val = clamp(max_boundary - adxl345_odr_tbl[odr][0],
> > > > >                           min_boundary, max_boundary);
> > > > > +             st->inact_time_ms = MILLI * val;
> > > > > +
> > > > > +             /* Inactivity time in s */
> > > > > +             return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
> > > > > +     } else if (val_int == 0 && val_fract > 0) {
> > > >
> > > > val_fract check is not needed here.
> > >
> > > Case for e.g. 0.123, numbers under 1s. This goes into the free-fall register.
> >
> > 0.0 is already checked above, and since the val_fract is unsigned this is check
> > is redundant.
> >
> > > > > +             /* time < 1s, free-fall */
> > > > > +
> > > > > +             /*
> > > > > +              * Datasheet max. value is 255 * 5000 us = 1.275000 seconds.
> > > > > +              *
> > > > > +              * Recommended values between 100ms and 350ms (0x14 to 0x46)
> > > > > +              */
> > > > > +             st->inact_time_ms = DIV_ROUND_UP(val_fract, MILLI);
> > > > > +
> > > > > +             return regmap_write(st->regmap, ADXL345_REG_TIME_FF,
> > > > > +                                 DIV_ROUND_CLOSEST(val_fract, 5));
> > > > > +     } else if (val_int > 0) {
> > > >
> > > > if now is redundant here, right?
> > >
> > > So, this will be 1s through 255s. Periods above 1sec. This goes into
> > > the inactivity register.
> >
> > See above,
> >
> 
> I agree, that checking for val_fract is actually done as a sub case of
> val_int, and only if val_int was 0. So, would the following make it
> clearer?
> 
> if (val_int  == 0) {
>     if (val_fract == 0) {
>         // 0 provided, default values
>     } else {
>         // >0s, e.g. 0.123s, use free-fall register
> } else {
>     // 1s - 255s, use inactivity register
> }
> 
> Actually - I did not touch that - I saw some places where I'm already
> using nested if/else in the third level. I guess, by the style advice
> according to switch/case, this also applies to if/else, right?
> 
> If yes, when the according parts go into another round, I might give
> it a try to separate as well using helper functions.

You can think through the patches. It might make sense to consider as well this

helper_1()
{
	// for default
}

helper_2()
{
	// for free-fall
}

helper_3()
{
	// for inactive
}

	...
	if ()
		helper_1();
	else if ()
		helper_2();
	else
		helper_3();


> > > > > +             /* Time >= 1s, inactivity */
> > > > > +             st->inact_time_ms = MILLI * val_int;
> > > > > +
> > > > > +             return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int);
> > > > >       }

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ