[PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq

Yasin Lee posted 4 patches 1 month, 2 weeks ago
[PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
Posted by Yasin Lee 1 month, 2 weeks ago
Avoid division by zero when sampling frequency is unspecified.

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 | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index ad839db6b326..17e00ee2b6f8 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -719,6 +719,9 @@ 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;
 
+	if (!val && !val2)
+		return -EINVAL;
+
 	period_ms = div_u64(NANO, (val * MEGA + val2));
 
 	for (i = 0; i < ARRAY_SIZE(hx9023s_samp_freq_table); i++) {

-- 
2.43.0
Re: [PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Fri, Feb 13, 2026 at 11:14:44PM +0800, Yasin Lee wrote:
> Avoid division by zero when sampling frequency is unspecified.

In case of agreement this is the desired behaviour you can add
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
Posted by Jonathan Cameron 1 month, 2 weeks ago
On Fri, 13 Feb 2026 18:39:16 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Fri, Feb 13, 2026 at 11:14:44PM +0800, Yasin Lee wrote:
> > Avoid division by zero when sampling frequency is unspecified.  
> 
> In case of agreement this is the desired behaviour you can add
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
It seems sensible to me as avoids undefined behaviour + is
unlikely to make any functional difference as I assume that whatever
we got from the undef never in practice matched a valid input.

So applied patches 1 and 2 to my fixes-togreg branch. I'm not pushing
that out just now though as I want rc1 to rebase it on first.

Thanks,

Jonathan

>
Re: [PATCH v3 2/4] iio: proximity: hx9023s: Protect against division by zero in set_samp_freq
Posted by Yasin Lee 1 month, 2 weeks ago
On Sun, Feb 15, 2026 at 1:43 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Fri, 13 Feb 2026 18:39:16 +0200
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
>
> > On Fri, Feb 13, 2026 at 11:14:44PM +0800, Yasin Lee wrote:
> > > Avoid division by zero when sampling frequency is unspecified.
> >
> > In case of agreement this is the desired behaviour you can add
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> It seems sensible to me as avoids undefined behaviour + is
> unlikely to make any functional difference as I assume that whatever
> we got from the undef never in practice matched a valid input.
>
> So applied patches 1 and 2 to my fixes-togreg branch. I'm not pushing
> that out just now though as I want rc1 to rebase it on first.
>
> Thanks,
>
> Jonathan
>

Hi Jonathan,

That's great! Thank you for applying the entire series, and thanks to
Andy and Krzysztof for the detailed review and guidance throughout the
process.

Best regards,
Yasin Lee

> >
>