]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
iio: adc: nxp-sar-adc: fix division by zero in write_raw
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Wed, 1 Apr 2026 15:29:24 +0000 (18:29 +0300)
committerJonathan Cameron <jic23@kernel.org>
Fri, 15 May 2026 11:00:21 +0000 (12:00 +0100)
commita9aba21a539c668a66b58eeb08ad3909e5a54c2a
treee848eb1032ee7736d0e3924a05af7f8639b38552
parent5aba4f94b225617a55fed442a70329b2ee19c0a5
iio: adc: nxp-sar-adc: fix division by zero in write_raw

Add a validation check for the sampling frequency value before using it
as a divisor. A user writing zero or a negative value to the
sampling_frequency sysfs attribute triggers a division by zero in the
kernel.

Also prevent unsigned integer underflow when the computed cycle count is
smaller than NXP_SAR_ADC_CONV_TIME, which would wrap the u32 inpsamp to
a huge value.

Fixes: 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/adc/nxp-sar-adc.c