[PATCH v2 0/6] iio: proximity: hx9023s: fix sampling frequency, resume and event value handling

From: Arnav Kapoor

Date: Thu Nov 26 2026 - 16:37:39 EST


Five fixes for the HX9023S capacitive proximity driver, and one cleanup.

1: writing 67108864 (or any value for which val * 10^6 + val2 is a
multiple of 2^32) to sampling_frequency divides by zero: div_u64()
takes a u32 divisor. The check added in a318cfc08537 only catches 0.
2: reading sampling_frequency indexes the 32-entry period table with
the PRF_CFG register value unchecked; the configuration file loaded
by hx9023s_bin_load() can put any 8-bit value there.
3: resume re-enables the chip interrupts only when the trigger is
enabled, so threshold events stop after the first suspend.
4: out-of-range threshold values are masked into the 10-bit field
instead of being rejected (-32 becomes the largest threshold).
5: same for the 4-bit debounce fields (16 becomes 0).
6: cleanup, no functional change: get_samp_freq() doesn't need a
64-bit division either.

Changes in v2:
- 1: use val == 0 && val2 == 0 for consistency (Andy)
- 1: reject 1 kHz and above (a period below the smallest table entry)
and use a plain 32-bit division instead of div64_u64() (Andy)
- 4: check val >= BIT(15), keep the threshold with & ~GENMASK(4, 0)
and add a comment on why the low bits are dropped (Andy)
- 6: new, drop the div_u64() in get_samp_freq() as well (Andy, on v1
2/5); last in the series as it isn't a fix
- Rebase on the current fixes-togreg

v1: https://lore.kernel.org/all/20261123165255.239490-1-kapoorarnav43@xxxxxxxxx/

Patch 2 assumes the whole PRF_CFG register is the period index, as the
driver already does; I don't have the datasheet to check whether it has
other fields.

Applies to both fixes-togreg and testing.
Compile-tested only (W=1 for every patch, checkpatch --strict clean); I
don't have HX9023S hardware. The checks in 1 and 4 were tested with a
userspace copy on 32-bit and 64-bit: all 32 table periods are still
accepted, and the threshold check matches the v1 one for every value.

Arnav Kapoor (6):
iio: proximity: hx9023s: fix division by zero in set_samp_freq
iio: proximity: hx9023s: check the sampling frequency index
iio: proximity: hx9023s: re-enable interrupts on resume for events
iio: proximity: hx9023s: reject out-of-range threshold values
iio: proximity: hx9023s: reject out-of-range debounce values
iio: proximity: hx9023s: use plain division in get_samp_freq

drivers/iio/proximity/hx9023s.c | 47 +++++++++++++++++++++++++--------
1 file changed, 36 insertions(+), 11 deletions(-)


base-commit: 69bf7489f01ffa3c3269d09eb8a0668b1bdfa053
--
2.53.0