Re: [PATCH 03/10] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
From: Andy Shevchenko
Date: Thu Nov 19 2026 - 12:24:45 EST
On Thu, Nov 19, 2026 at 03:30:36PM +0000, Lee Jones wrote:
> When reading IIO_CHAN_INFO_SAMP_FREQ, adxl313_read_raw() extracts the
> 4-bit rate field (0..15) from ADXL313_REG_BW_RATE and subtracts
> ADXL313_RATE_BASE (6) to index adxl313_odr_freqs[].
>
> ADXL312 and ADXL314 support sub-6.25 Hz rate codes 0..5 and do not
> perform a soft reset during setup, and debugfs register writes or a
> faulty bus read can likewise yield codes below ADXL313_RATE_BASE. When
> that happens, subtracting ADXL313_RATE_BASE produces a negative index
> and reads before the start of adxl313_odr_freqs[].
>
> Return -EINVAL if the rate field is below ADXL313_RATE_BASE.
...
> - ret = FIELD_GET(ADXL313_RATE_MSK, regval) - ADXL313_RATE_BASE;
> + regval = FIELD_GET(ADXL313_RATE_MSK, regval);
> + if (regval < ADXL313_RATE_BASE)
> + return -EINVAL;
Here seems ERANGE is good.
> + ret = regval - ADXL313_RATE_BASE;
--
With Best Regards,
Andy Shevchenko