* [PATCH v2 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check
2026-10-09 22:24 [PATCH v2 0/2] iio: adc: ti-ads112c14: minor fixes David Lechner (TI)
@ 2026-10-09 22:24 ` David Lechner (TI)
2026-10-09 22:24 ` [PATCH v2 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back David Lechner (TI)
2026-10-18 2:01 ` [PATCH v2 0/2] iio: adc: ti-ads112c14: minor fixes Jonathan Cameron
2 siblings, 0 replies; 4+ messages in thread
From: David Lechner (TI) @ 2026-10-09 22:24 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner (TI), Sashiko
Fix checking for negative values when writing the settlingtime
attribute. MICRO is an unsigned long, so on 32-bit architectures,
integer * MICRO is evaluated as a 32-bit unsigned value. A negative
integer part is then zero-extended to a positive s64 and passes the
< 0 check. Large positive values can also wrap around.
Reject negative input before doing the multiplication and do the
multiplication as 64-bit.
Fixes: 839cbb1e2331 ("iio: adc: ti-ads112c14: add settlingtime attribute")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/message/20260910-iio-adc-ti-ads112c14-filter-support-v3-9-e5a9b27ddb1a%40baylibre.com
Signed-off-by: David Lechner (TI) <dlechner@baylibre.com>
---
drivers/iio/adc/ti-ads112c14.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
index 3c877126b0be..d8fa8d413e87 100644
--- a/drivers/iio/adc/ti-ads112c14.c
+++ b/drivers/iio/adc/ti-ads112c14.c
@@ -653,7 +653,7 @@ static int ads112c14_get_settling_time_us(struct ads112c14_data *data,
static int ads112c14_find_delay_for_settling_time_us(struct ads112c14_data *data,
struct ads112c14_channel_state *channel_state,
- s64 settling_time_us, u8 *delay)
+ u64 settling_time_us, u8 *delay)
{
u64 delay_us, delay_tmod_needed;
u32 fixed_latency_us;
@@ -719,7 +719,7 @@ static ssize_t ads112c14_write_settling_time(struct iio_dev *indio_dev,
{
struct ads112c14_data *data = iio_priv(indio_dev);
struct ads112c14_channel_state *channel_state;
- s64 settling_time_us;
+ u64 settling_time_us;
int integer;
int fract;
u8 delay;
@@ -729,10 +729,11 @@ static ssize_t ads112c14_write_settling_time(struct iio_dev *indio_dev,
if (ret)
return ret;
- settling_time_us = integer * MICRO + fract;
- if (settling_time_us < 0)
+ if (integer < 0 || fract < 0)
return -EINVAL;
+ settling_time_us = (u64)integer * MICRO + fract;
+
IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back
2026-10-09 22:24 [PATCH v2 0/2] iio: adc: ti-ads112c14: minor fixes David Lechner (TI)
2026-10-09 22:24 ` [PATCH v2 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check David Lechner (TI)
@ 2026-10-09 22:24 ` David Lechner (TI)
2026-10-18 2:01 ` [PATCH v2 0/2] iio: adc: ti-ads112c14: minor fixes Jonathan Cameron
2 siblings, 0 replies; 4+ messages in thread
From: David Lechner (TI) @ 2026-10-09 22:24 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner (TI), Sashiko
Fix the settlingtime attribute so that writing back the value that was
read does not change the setting.
Reading the attribute rounds the total settling time down to the nearest
microsecond. Writing it subtracted the fixed latency (also rounded down
to the nearest microsecond) and then rounded the remaining delay up to
the next tmod period. These don't agree, so writing back the value just
read could select the next higher DELAY value, causing the settling time
to creep up on each write.
Instead, convert the requested total settling time to tmod periods
(rounding up) and compare that against the fixed latency plus delay in
tmod periods. This picks the smallest DELAY value that reads back as
greater than or equal to the requested value.
Fixes: 839cbb1e2331 ("iio: adc: ti-ads112c14: add settlingtime attribute")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/message/20260910-iio-adc-ti-ads112c14-filter-support-v3-9-e5a9b27ddb1a%40baylibre.com
Signed-off-by: David Lechner (TI) <dlechner@baylibre.com>
---
drivers/iio/adc/ti-ads112c14.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
index d8fa8d413e87..c0374bd8d001 100644
--- a/drivers/iio/adc/ti-ads112c14.c
+++ b/drivers/iio/adc/ti-ads112c14.c
@@ -655,29 +655,22 @@ static int ads112c14_find_delay_for_settling_time_us(struct ads112c14_data *data
struct ads112c14_channel_state *channel_state,
u64 settling_time_us, u8 *delay)
{
- u64 delay_us, delay_tmod_needed;
- u32 fixed_latency_us;
- int ret, fmod_Hz;
+ int latency_tmod, fmod_Hz;
+ u64 total_tmod_needed;
u8 i;
- ret = ads112c14_get_settling_time_us(data, channel_state, 0, &fixed_latency_us);
- if (ret)
- return ret;
-
- if (settling_time_us <= fixed_latency_us) {
- *delay = 0;
- return 0;
- }
-
fmod_Hz = ads112c14_get_fmod_Hz(data, channel_state);
if (fmod_Hz <= 0)
return -EINVAL;
- delay_us = settling_time_us - fixed_latency_us;
- delay_tmod_needed = DIV_ROUND_UP_ULL(delay_us * fmod_Hz, USEC_PER_SEC);
+ latency_tmod = ads112c14_get_latency_tmod(channel_state);
+ if (latency_tmod < 0)
+ return latency_tmod;
+
+ total_tmod_needed = DIV_ROUND_UP_ULL(settling_time_us * fmod_Hz, USEC_PER_SEC);
- for (i = 1; i < ADS112C14_DELAY_MAX; i++) {
- if (ads112c14_delay_to_tmod(i) >= delay_tmod_needed)
+ for (i = 0; i < ADS112C14_DELAY_MAX; i++) {
+ if (latency_tmod + ads112c14_delay_to_tmod(i) >= total_tmod_needed)
break;
}
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2 0/2] iio: adc: ti-ads112c14: minor fixes
2026-10-09 22:24 [PATCH v2 0/2] iio: adc: ti-ads112c14: minor fixes David Lechner (TI)
2026-10-09 22:24 ` [PATCH v2 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check David Lechner (TI)
2026-10-09 22:24 ` [PATCH v2 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back David Lechner (TI)
@ 2026-10-18 2:01 ` Jonathan Cameron
2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-10-18 2:01 UTC (permalink / raw)
To: David Lechner (TI)
Cc: Nuno Sá,
Andy Shevchenko, Jonathan Cameron, linux-iio, linux-kernel,
Sashiko
On Fri, 09 Oct 2026 17:24:56 -0500
"David Lechner (TI)" <dlechner@baylibre.com> wrote:
> Jonathan picked up the filter series for TI ADS112C14 already, but there
> were a few minor things Sashiko found that seemed worth fixing.
>
> https://lore.kernel.org/linux-iio/20260913211128.25734544@jic23-hlaptop/
>
> Signed-off-by: David Lechner (TI) <dlechner@baylibre.com>
Give you are building on the driver with other series, my inclination
is to not rush these. So for now I've applied them to the testing branch
of iio.git, but shout if I should do differently!
Thanks,
Jonathan
> ---
> Changes in v2:
> - Change settling_time_us to u64.
> - Link to v1: https://patch.msgid.link/20260925-iio-adc-ti-ads112c14-fix-settlingtime-sign-v1-0-1fd53e7242e8@baylibre.com
>
> ---
> David Lechner (TI) (2):
> iio: adc: ti-ads112c14: fix negative settlingtime check
> iio: adc: ti-ads112c14: fix settlingtime creep on write back
>
> drivers/iio/adc/ti-ads112c14.c | 34 ++++++++++++++--------------------
> 1 file changed, 14 insertions(+), 20 deletions(-)
> ---
> base-commit: d8c0f48f0b1583308a98401c0c7b1a65d1d43a6c
> change-id: 20260925-iio-adc-ti-ads112c14-fix-settlingtime-sign-a8e34f974d24
>
> Best regards,
> --
> David Lechner (TI) <dlechner@baylibre.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread