Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] drivers/iio/adc/ad7124.c: fix division by zero in ad7124_set_channel_odr()
@ 2024-10-22 13:43 Zicheng Qu
  2024-10-22 14:23 ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Zicheng Qu @ 2024-10-22 13:43 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, alexandru.tachici, linux-iio,
	linux-kernel
  Cc: tanghui20, zhangqiao22, judy.chenhui, quzicheng

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>
---
 drivers/iio/adc/ad7124.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index a5d91933f505..b79c48d46ccc 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -637,7 +637,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;
 		}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-22 20:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 13:43 [PATCH] drivers/iio/adc/ad7124.c: fix division by zero in ad7124_set_channel_odr() Zicheng Qu
2024-10-22 14:23 ` Nuno Sá
2024-10-22 20:08   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox