From: Dan Carpenter <dan.carpenter@linaro.org>
To: Mike Looijmans <mike.looijmans@topic.nl>
Cc: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] iio: adc: ti-ads1298: prevent divide by zero in ads1298_set_samp_freq()
Date: Thu, 22 Feb 2024 09:15:37 +0300 [thread overview]
Message-ID: <c32c9087-86de-423b-8101-67b4a7f9d728@moroto.mountain> (raw)
In-Reply-To: <5f393a87-ca8b-4e68-a6f4-a79f75a91ccb@moroto.mountain>
The "val" variable comes from the user so we need to ensure that it's not
zero. In fact, all negative values are invalid as well. Add a check for
that.
Fixes: 00ef7708fa60 ("iio: adc: ti-ads1298: Add driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
I wrote this commit message in a very confident tone of voice and I have
spent a long time looking at this code so I'm reasonably sure this
patch is correct. However, I'm not super familiar with this subsystem
so probably you should double check.
drivers/iio/adc/ti-ads1298.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/adc/ti-ads1298.c b/drivers/iio/adc/ti-ads1298.c
index 67637f1abdc7..1d1eaba3d6d1 100644
--- a/drivers/iio/adc/ti-ads1298.c
+++ b/drivers/iio/adc/ti-ads1298.c
@@ -258,6 +258,8 @@ static int ads1298_set_samp_freq(struct ads1298_private *priv, int val)
rate = ADS1298_CLK_RATE_HZ;
if (!rate)
return -EINVAL;
+ if (val <= 0)
+ return -EINVAL;
factor = (rate >> ADS1298_SHIFT_DR_HR) / val;
if (factor >= BIT(ADS1298_SHIFT_DR_LP))
--
2.43.0
next prev parent reply other threads:[~2024-02-22 6:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 6:14 [PATCH 1/2] iio: adc: ti-ads1298: Fix error code in probe() Dan Carpenter
2024-02-22 6:15 ` Dan Carpenter [this message]
2024-02-22 7:10 ` Mike Looijmans
2024-02-24 18:13 ` Jonathan Cameron
2024-02-26 7:45 ` Dan Carpenter
2024-02-26 14:37 ` Andy Shevchenko
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=c32c9087-86de-423b-8101-67b4a7f9d728@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jic23@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.looijmans@topic.nl \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.