Re: [PATCH 1/2] iio: adc: ti-ads112c14: fix negative settlingtime check
From: Jonathan Cameron
Date: Fri Sep 25 2026 - 20:23:14 EST
On Fri, 25 Sep 2026 16:27:43 -0500
"David Lechner (TI)" <dlechner@xxxxxxxxxxxx> 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@xxxxxxxxxx>
> Closes: https://sashiko.dev/#/message/20260910-iio-adc-ti-ads112c14-filter-support-v3-9-e5a9b27ddb1a%40baylibre.com
> Signed-off-by: David Lechner (TI) <dlechner@xxxxxxxxxxxx>
> ---
> 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;
>