From: Yasin Lee <yasin.lee.x@gmail.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
yasin.lee.x@outlook.com
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, Yasin Lee <yasin.lee.x@gmail.com>
Subject: [PATCH v2 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
Date: Thu, 12 Feb 2026 14:26:53 +0800 [thread overview]
Message-ID: <20260212-upstream-20260219-v2-2-2b28fce5d09e@gmail.com> (raw)
In-Reply-To: <20260212-upstream-20260219-v2-0-2b28fce5d09e@gmail.com>
Avoid division by zero when sampling frequency is unspecified by
falling back to a default 100ms sampling period.
Fixes: 60df548277b7 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
Signed-off-by: Yasin Lee <yasin.lee.x@gmail.com>
---
drivers/iio/proximity/hx9023s.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index ad839db6b326..e714fe00a44e 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -719,7 +719,11 @@ static int hx9023s_set_samp_freq(struct hx9023s_data *data, int val, int val2)
struct device *dev = regmap_get_device(data->regmap);
unsigned int i, period_ms;
- period_ms = div_u64(NANO, (val * MEGA + val2));
+ if (val || val2)
+ period_ms = div_u64(NANO, (val * MEGA + val2));
+ else
+ /* Fallback to a safe default sampling period */
+ period_ms = 100;
for (i = 0; i < ARRAY_SIZE(hx9023s_samp_freq_table); i++) {
if (period_ms == hx9023s_samp_freq_table[i])
--
2.43.0
next prev parent reply other threads:[~2026-02-12 6:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 6:26 [PATCH v2 0/4] iio: proximity: hx9023s: firmware property, safety fixes Yasin Lee
2026-02-12 6:26 ` [PATCH v2 1/4] iio: proximity: hx9023s: fix out-of-bounds access when copying firmware Yasin Lee
2026-02-12 10:58 ` Andy Shevchenko
2026-02-12 11:25 ` Krzysztof Kozlowski
2026-02-12 13:48 ` Andy Shevchenko
2026-02-12 16:27 ` Krzysztof Kozlowski
2026-02-12 6:26 ` Yasin Lee [this message]
2026-02-12 10:55 ` [PATCH v2 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq Andy Shevchenko
2026-02-12 16:44 ` Yasin Lee
2026-02-12 20:01 ` Andy Shevchenko
2026-02-12 6:26 ` [PATCH v2 3/4] dt-bindings: iio: proximity: hx9023s: support firmware-name property Yasin Lee
2026-02-12 11:23 ` Krzysztof Kozlowski
2026-02-12 17:36 ` Yasin Lee
2026-02-12 6:26 ` [PATCH v2 4/4] " Yasin Lee
2026-02-12 10:57 ` 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=20260212-upstream-20260219-v2-2-2b28fce5d09e@gmail.com \
--to=yasin.lee.x@gmail.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=yasin.lee.x@outlook.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