Re: [PATCH 2/5] iio: proximity: hx9023s: check the sampling frequency index
From: Andy Shevchenko
Date: Mon Nov 23 2026 - 14:16:03 EST
On Mon, Nov 23, 2026 at 10:22:48PM +0530, Arnav Kapoor wrote:
> hx9023s_get_samp_freq() uses the PRF_CFG register value as an index
> into hx9023s_samp_freq_table[], which has 32 entries, without checking
> it. The driver only writes valid indexes itself, but the configuration
> file loaded by hx9023s_bin_load() writes arbitrary register/value pairs,
> so PRF_CFG can hold any 8-bit value. Reading sampling_frequency then
> reads past the end of the table and divides KILO by whatever it finds
> there, which may be zero.
>
> Return -EINVAL if the index is outside the table.
...
> odr = hx9023s_samp_freq_table[index];
> *val = KILO / odr;
> *val2 = div_u64((KILO % odr) * MICRO, odr);
Side note: Also here, strange to see 64-bit division where it's not required.
--
With Best Regards,
Andy Shevchenko