Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Nuno Sá" <noname.nuno@gmail.com>
Cc: Zicheng Qu <quzicheng@huawei.com>,
	lars@metafoo.de, Michael.Hennerich@analog.com,
	alexandru.tachici@analog.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, tanghui20@huawei.com,
	zhangqiao22@huawei.com, judy.chenhui@huawei.com
Subject: Re: [PATCH] drivers/iio/adc/ad7124.c: fix division by zero in ad7124_set_channel_odr()
Date: Tue, 22 Oct 2024 21:08:42 +0100	[thread overview]
Message-ID: <20241022210842.2b917750@jic23-huawei> (raw)
In-Reply-To: <561655d4b3bd063cb6ee339294ab9c62a5b06d53.camel@gmail.com>

On Tue, 22 Oct 2024 16:23:17 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Tue, 2024-10-22 at 13:43 +0000, Zicheng Qu wrote:
> > 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>
> > ---  
> 
> LGTM,
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
As with the other patch, I fixed up the patch title to match local style.

Applied to the fixes-togreg branch of iio.git

Thanks,

Jonathan

> 
> >  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;
> >  		}  
> 


      reply	other threads:[~2024-10-22 20:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241022210842.2b917750@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=alexandru.tachici@analog.com \
    --cc=judy.chenhui@huawei.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=noname.nuno@gmail.com \
    --cc=quzicheng@huawei.com \
    --cc=tanghui20@huawei.com \
    --cc=zhangqiao22@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox