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: <DEOK8E55YR0L.3ST80EKZ08QE8@gmail.com>
Date: Wed, 03 Dec 2025 06:54:46 -0500
From: "Kurt Borja" <kuurtb@...il.com>
To: "Andy Shevchenko" <andriy.shevchenko@...el.com>, "Kurt Borja"
 <kuurtb@...il.com>
Cc: "Jonathan Cameron" <jic23@...nel.org>, "Rob Herring" <robh@...nel.org>,
 "Krzysztof Kozlowski" <krzk+dt@...nel.org>, "Conor Dooley"
 <conor+dt@...nel.org>, "Tobias Sperling" <tobias.sperling@...ting.com>,
 "David Lechner" <dlechner@...libre.com>, Nuno Sá
 <nuno.sa@...log.com>, "Andy Shevchenko" <andy@...nel.org>,
 <linux-iio@...r.kernel.org>, <devicetree@...r.kernel.org>,
 <linux-kernel@...r.kernel.org>, "Jonathan Cameron"
 <Jonathan.Cameron@...wei.com>
Subject: Re: [PATCH v4 2/2] iio: adc: Add ti-ads1018 driver

On Wed Dec 3, 2025 at 3:58 AM -05, Andy Shevchenko wrote:
> On Tue, Dec 02, 2025 at 11:56:19PM -0500, Kurt Borja wrote:
>> Add ti-ads1018 driver for Texas Instruments ADS1018 and ADS1118 SPI
>> analog-to-digital converters.
>> 
>> These chips' MOSI pin is shared with a data-ready interrupt. Defining
>> this interrupt in devicetree is optional, therefore we only create an
>> IIO trigger if one is found.
>> 
>> Handling this interrupt requires some considerations. When enabling the
>> trigger the CS line is tied low (active), thus we need to hold
>> spi_bus_lock() too, to avoid state corruption. This is done inside the
>> set_trigger_state() callback, to let users use other triggers without
>> wasting a bus lock.
>
> ...
>
>> +/**
>> + * ADS1018_FSR_TO_SCALE - Converts FSR into scale
>> + * @_fsr: Full-scale range in millivolts
>> + * @_res: ADC resolution
>> + *
>> + * The macro is crafted to avoid potential overflows on 32-bit machines. This
>> + * imposes restrictions on the possible values for @_fsr (less than 274878),
>
>> + * and @_res (greater than or equal to 6 bits).
>
> This is actually incorrect. See below.

I'll fix this!

>
>> + * Return: Scale in IIO_VAL_INT_PLUS_NANO format
>> + */
>> +#define ADS1018_FSR_TO_SCALE(_fsr, _res) \
>> +	{ 0, ((_fsr) * (MICRO >> 6)) / (BIT((_res) - 1) >> 6) }
>
> This is different from what I suggested. But I think I was mistaken with
> the parentheses and thought that you are dividing on the mask-like value.
>
> If the current version correct by the result, first of all, the limitation for

The calculation is correct because I sum one in all cases bellow
(advertised resolution).

> @_res is 7 and not 6. And second, it can be rewritten in a simpler form.
>
> 	{ 0, ((_fsr) * (MICRO >> 6)) >> ((_res) - 6 - 1) }

I wanted to use (>> 6) in the numerator and denominator to make it clear
it cancels out. But that (- 6) is equivalent so I can change it.

>
> Please, check it again.

Thanks!


-- 
 ~ Kurt


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ