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:   Mon, 6 Mar 2023 15:44:23 +0100
From:   Mike Looijmans <mike.looijmans@...ic.nl>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
CC:     devicetree@...r.kernel.org, linux-iio@...r.kernel.org,
        Caleb Connolly <caleb.connolly@...aro.org>,
        ChiYuan Huang <cy_huang@...htek.com>,
        ChiaEn Wu <chiaen_wu@...htek.com>,
        Cosmin Tanislav <demonsingur@...il.com>,
        Ibrahim Tilki <Ibrahim.Tilki@...log.com>,
        Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Marcus Folkesson <marcus.folkesson@...il.com>,
        Ramona Bolboaca <ramona.bolboaca@...log.com>,
        William Breathitt Gray <william.gray@...aro.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 2/2] iio: adc: Add TI ADS1100 and ADS1000


Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert


TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: mike.looijmans@...icproducts.com
W: www.topic.nl

Please consider the environment before printing this e-mail
On 06-03-2023 14:29, Andy Shevchenko wrote:
> On Mon, Mar 06, 2023 at 02:13:12PM +0100, Mike Looijmans wrote:
>> The ADS1100 is a 16-bit ADC (at 8 samples per second).
>> The ADS1000 is similar, but has a fixed data rate.
> ...
>
>> +	microvolts = regulator_get_voltage(data->reg_vdd);
>> +	/*
>> +	 * val2 is in 'micro' units, n = val2 / 1000000
>> +	 * result must be millivolts, d = microvolts / 1000
>> +	 * the full-scale value is d/n, corresponds to 2^15,
>> +	 * hence the gain = (d / n) >> 15, factoring out the 1000 and moving the
>> +	 * bitshift so everything fits in 32-bits yields this formula.
>> +	 */
>> +	gain = ((microvolts + BIT(14)) >> 15) * 1000 / val2;
> Perhaps adding MICROVOLT_PER_MILLIVOLT (to units.h) and use it here?

Would that require a separate patch?

I fear that would get feedback like "why not MICROCOULOB_PER_MILLICOULOMB".

If I fill in the equation then that "1000" is actually 
MICROVOLT_PER_MICROVOLT_PER_MILLIVOLT, which would evaluate to simply 
"MILLIVOLT".


>
> Besides that it's seems like
>
> 	microvolts = regulator_get_voltage(data->reg_vdd);
> 	gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) *
> 	       MICROVOLT_PER_MILLIVOLT / val2;

Yeah, the DIV_ROUNDUP_CLOSEST is more readable.


>> +	if (gain <= 0 || gain > 8)
>> +		return -EINVAL;
> As I commented out in the previous discussion (please, give a chance to the
> reviewers to answer before issuing a new version of the series) this better
> to be
>
> 	if (gain < BIT(0) || gain > BIT(3))
>
> which will show the nature of power of two implicitly.
>
>> +	regval = ffs(gain) - 1;
>> +	ads1100_set_config_bits(data, ADS1100_PGA_MASK, regval);
> Can be unified in one line.

Combining it all, I'd arrive at this code:

     gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) * MILLI / val2;
     if (gain < BIT(0) || gain > BIT(3))
         return -EINVAL;

     ads1100_set_config_bits(data, ADS1100_PGA_MASK, ffs(gain) - 1);


>> +	return 0;
>> +}
> ...
>
>> +			return ads1100_set_config_bits(
>> +					data, ADS1100_DR_MASK,
>> +					FIELD_PREP(ADS1100_DR_MASK, i));
> Wrong indentation.
> Please, check all your code for this kind of issues.
>
I always run it through checkpatch.pl but that didn't report on this 
indentation.

A bit of digging in the scripts directory yields "Lindent". Feeding my 
file to that indeed changes those lines (and some others too). I'll run 
my next patch through that.

-- 
Mike Looijmans

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ