iio: proximity: hx9023s: Protect against division by zero in set_samp_freq

Avoid division by zero when sampling frequency is unspecified.

Fixes: 60df548277 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
Signed-off-by: Yasin Lee <yasin.lee.x@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Yasin Lee
2026-02-13 23:14:44 +08:00
committed by Jonathan Cameron
parent 585b90c016
commit a318cfc085

View File

@@ -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++) {