iio: proximity: sx9360: use an int array for the sampling frequency range
PATCH 1/1 iio: proximity: sx9360: use an int array for the sampling frequency range
sx9360_samp_freq_interval[] is an array of struct { int val; int val2; } that read_avail() hands to the IIO core by casting it to int *. That relies on the struct having no padding. Declare it as an array of int[2], like other IIO drivers do for their available ranges, so the layout is plain and the cast no longer drops const.
No functional change.
---
This is the int array conversion Andy suggested while reviewing the sampling frequency fix. It goes on top of that fix, commit d252425c1533 ("iio: proximity: sx9360: fix sampling frequency write and available range") in fixes-togreg, so it can wait until that reaches togreg.
Compile-tested only (W=1); I don't have SX9360 hardware.
drivers/iio/proximity/sx9360.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/proximity/sx9360.c +2 -5
@@ -181,10 +181,7 @@ static const struct iio_chan_spec sx9360_channels[] = {* The interval is not linear, but given there is 2047 possible value, * Returns the fake increment of (Max-Min)/2047 */ -static const struct { -int val; -int val2; -} sx9360_samp_freq_interval[] = { +static const int sx9360_samp_freq_interval[][2 ] = { {0 ,238535 },/* 4MHz / (8192 * 2047) */ {0 ,238419 }, {488 ,281250 },/* 4MHz / 8192 */
@@ -376,7 +373,7 @@ static int sx9360_read_avail(struct iio_dev *indio_dev,case IIO_CHAN_INFO_SAMP_FREQ : *type =IIO_VAL_INT_PLUS_MICRO ; *length =ARRAY_SIZE (sx9360_samp_freq_interval) *2 ; - *vals = (int *)sx9360_samp_freq_interval; + *vals = (const int *)sx9360_samp_freq_interval;return IIO_AVAIL_RANGE ;default :return -EINVAL ;
base-commit: 340d44bdf9db0f095f99845b5ad8628781d79b6f
Signature · 1 line
2.53.0
Quoted 7 lines · Arnav Kapoor
sx9360_samp_freq_interval[] is an array of struct { int val; int val2; } that
read_avail()hands to the IIO core by casting it to int *. That relies on the struct having no padding. Declare it as an array of int[2], like other IIO drivers do for their available ranges, so the layout is plain and the cast no longer drops const.No functional change.
LGTM,
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 7 lines · On Wed, 4 Nov 2026 23:56:31 +0200 Andy Shevchenko…
Quoted 6 lines · Arnav Kapoor
sx9360_samp_freq_interval[] is an array of struct { int val; int val2; } that
read_avail()hands to the IIO core by casting it to int *. That relies on the struct having no padding. Declare it as an array of int[2], like other IIO drivers do for their available ranges, so the layout is plain and the cast no longer drops const.
Quoted 6 lines
Quoted 1 line
No functional change.
LGTM,
Reviewed-by Andy Shevchenko <[email protected]>
Looks fine but will have to wait for the fix that touched this code to make it to upstream for non fixes.