mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/6] iio: proximity: hx9023s: fix sampling frequency, resume and event value handling
@ 2026-12-04 16:27 Arnav Kapoor
  2026-12-04 16:27 ` [PATCH v3 1/6] iio: proximity: hx9023s: fix division by zero in set_samp_freq Arnav Kapoor
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Arnav Kapoor @ 2026-12-04 16:27 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: David Lechner, Nuno Sá,
	Andy Shevchenko, Andy Shevchenko, Yasin Lee, linux-iio,
	linux-kernel, Arnav Kapoor

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 v3:
- 1: compare with 1 * HZ_PER_KHZ, and write the division with named
  constants, MSEC_PER_SEC * MICRO / (val * MICRO + val2), with a
  comment on the units: val2 is in micro-units, so the frequency is
  counted in uHz (Andy). Same values as v2 for every input.
- 4: reverse xmas tree order for the locals, and the comment moved to
  the line it describes (Andy)
- Rebase on the current fixes-togreg

v2: https://lore.kernel.org/all/20261126213710.1047676-1-kapoorarnav43@gmail.com/
v1: https://lore.kernel.org/all/20261123165255.239490-1-kapoorarnav43@gmail.com/

Yasin, if you could test these on hardware, Jonathan would like that
before taking them; I don't have an HX9023S.

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).
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 | 55 ++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 11 deletions(-)


base-commit: 23c47e17ad8c18057f17be2a5beeccde9b5ca112
-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-04 17:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 16:27 [PATCH v3 0/6] iio: proximity: hx9023s: fix sampling frequency, resume and event value handling Arnav Kapoor
2026-12-04 16:27 ` [PATCH v3 1/6] iio: proximity: hx9023s: fix division by zero in set_samp_freq Arnav Kapoor
2026-12-04 16:27 ` [PATCH v3 2/6] iio: proximity: hx9023s: check the sampling frequency index Arnav Kapoor
2026-12-04 16:28 ` [PATCH v3 3/6] iio: proximity: hx9023s: re-enable interrupts on resume for events Arnav Kapoor
2026-12-04 16:28 ` [PATCH v3 4/6] iio: proximity: hx9023s: reject out-of-range threshold values Arnav Kapoor
2026-12-04 16:28 ` [PATCH v3 5/6] iio: proximity: hx9023s: reject out-of-range debounce values Arnav Kapoor
2026-12-04 16:28 ` [PATCH v3 6/6] iio: proximity: hx9023s: use plain division in get_samp_freq Arnav Kapoor
2026-12-04 17:44   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®