[PATCH 2/5] iio: proximity: hx9023s: check the sampling frequency index
From: Arnav Kapoor
Date: Mon Nov 23 2026 - 11:53:22 EST
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.
Fixes: e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
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 eaf962c29256..364ad2fd6095 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -681,6 +681,9 @@ static int hx9023s_get_samp_freq(struct hx9023s_data *data, int *val, int *val2)
if (ret)
return ret;
+ if (index >= ARRAY_SIZE(hx9023s_samp_freq_table))
+ return -EINVAL;
+
odr = hx9023s_samp_freq_table[index];
*val = KILO / odr;
*val2 = div_u64((KILO % odr) * MICRO, odr);
--
2.53.0