* [PATCH 0/2] iio: adc: ti-ads112c14: minor fixes
@ 2026-09-25 21:27 David Lechner (TI)
2026-09-25 21:27 ` [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check David Lechner (TI)
2026-09-25 21:27 ` [PATCH 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back David Lechner (TI)
0 siblings, 2 replies; 4+ messages in thread
From: David Lechner (TI) @ 2026-09-25 21:27 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Andy Shevchenko
Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner (TI), Sashiko
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>
---
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 | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 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
* [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check
2026-09-25 21:27 [PATCH 0/2] iio: adc: ti-ads112c14: minor fixes David Lechner (TI)
@ 2026-09-25 21:27 ` David Lechner (TI)
2026-09-26 0:23 ` Jonathan Cameron
2026-09-25 21:27 ` [PATCH 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back David Lechner (TI)
1 sibling, 1 reply; 4+ messages in thread
From: David Lechner (TI) @ 2026-09-25 21:27 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 | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
index 3c877126b0be..483f159e2836 100644
--- a/drivers/iio/adc/ti-ads112c14.c
+++ b/drivers/iio/adc/ti-ads112c14.c
@@ -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 = (s64)integer * MICRO + fract;
+
IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back
2026-09-25 21:27 [PATCH 0/2] iio: adc: ti-ads112c14: minor fixes David Lechner (TI)
2026-09-25 21:27 ` [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check David Lechner (TI)
@ 2026-09-25 21:27 ` David Lechner (TI)
1 sibling, 0 replies; 4+ messages in thread
From: David Lechner (TI) @ 2026-09-25 21:27 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 483f159e2836..3f46ebb3d84d 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,
s64 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.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check
2026-09-25 21:27 ` [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check David Lechner (TI)
@ 2026-09-26 0:23 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-09-26 0:23 UTC (permalink / raw)
To: David Lechner (TI)
Cc: Nuno Sá,
Andy Shevchenko, Jonathan Cameron, linux-iio, linux-kernel,
Sashiko
On Fri, 25 Sep 2026 16:27:43 -0500
"David Lechner (TI)" <dlechner@baylibre.com> wrote:
> 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 | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> index 3c877126b0be..483f159e2836 100644
> --- a/drivers/iio/adc/ti-ads112c14.c
> +++ b/drivers/iio/adc/ti-ads112c14.c
> @@ -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 = (s64)integer * MICRO + fract;
Hi David,
Given you sanity checked that this can't be negative, is it worth changing
settling_time_us to a u64 to reflect that?
Jonathan
> +
> IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> if (IIO_DEV_ACQUIRE_FAILED(claim))
> return -EBUSY;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-26 0:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25 21:27 [PATCH 0/2] iio: adc: ti-ads112c14: minor fixes David Lechner (TI)
2026-09-25 21:27 ` [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check David Lechner (TI)
2026-09-26 0:23 ` Jonathan Cameron
2026-09-25 21:27 ` [PATCH 2/2] iio: adc: ti-ads112c14: fix settlingtime creep on write back David Lechner (TI)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®