]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7124: fix division by zero in ad7124_set_channel_odr()
authorZicheng Qu <quzicheng@huawei.com>
Tue, 22 Oct 2024 13:43:30 +0000 (13:43 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Nov 2024 15:25:54 +0000 (16:25 +0100)
commit efa353ae1b0541981bc96dbf2e586387d0392baa upstream.

In the ad7124_write_raw() function, parameter val can potentially
be zero. This may lead to a division by zero when DIV_ROUND_CLOSEST()
is called within ad7124_set_channel_odr(). The ad7124_write_raw()
function is invoked through the sequence: iio_write_channel_raw() ->
iio_write_channel_attribute() -> iio_channel_write(), with no checks
in place to ensure val is non-zero.

Cc: stable@vger.kernel.org
Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels")
Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20241022134330.574601-1-quzicheng@huawei.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/adc/ad7124.c

index 471e1311e00773443d4f76965c110ef70481faee..06a541fa3cfea31ccfebb46dc958b272c87e485f 100644 (file)
@@ -596,7 +596,7 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
 
        switch (info) {
        case IIO_CHAN_INFO_SAMP_FREQ:
-               if (val2 != 0) {
+               if (val2 != 0 || val == 0) {
                        ret = -EINVAL;
                        break;
                }