ad7779_set_sampling_frequency() computes freq_khz = sampling_freq / HZ_PER_KHZ and then divides AD7779_HIGHPOWER_DIV by freq_khz. Only upper bounds are validated; there is no lower bound. Writing a sampling_frequency between 0 and 999 to the attribute therefore makes freq_khz 0 and the following division raises a divide error in the kernel: dec = div / freq_khz; frac = div % freq_khz; iio_write_channel_info() passes the parsed integer straight to write_raw(), so writing the attribute can trigger this. The driver computes the divisor in whole kHz, so reject anything smaller than HZ_PER_KHZ up front. Fixes: c9a3f8c7bfcb ("drivers: iio: adc: add support for ad777x family") Cc: stable@vger.kernel.org Reviewed-by: Arnav Kapoor Signed-off-by: Shirong Zhao --- v3: - Rephrase the trigger: IIO writable attributes are mode 0200, so drop the "unprivileged" wording. - Give "the driver computes the divisor in whole kHz" as the reason for the 1 kHz lower bound instead of claiming a hardware limit. - Add Reviewed-by from Arnav Kapoor. --- drivers/iio/adc/ad7779.c | 4 ++++ 1 file changed, 4 insertions(+) --- drivers/iio/adc/ad7779.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c index 79fb38d..537c281 100644 --- a/drivers/iio/adc/ad7779.c +++ b/drivers/iio/adc/ad7779.c @@ -278,6 +278,10 @@ static int ad7779_set_sampling_frequency(struct ad7779_state *st, if (sampling_freq > AD7779_SPIMODE_MAX_SAMP_FREQ) return -EINVAL; + /* freq_khz is a divisor below; it is zero for sampling_freq < 1 kHz */ + if (sampling_freq < HZ_PER_KHZ) + return -EINVAL; + div = AD7779_HIGHPOWER_DIV; freq_khz = sampling_freq / HZ_PER_KHZ; -- 2.53.0