Re: [PATCH v2] iio: light: veml3328: reshape scale array for readability
Joshua Crofts <[email protected]> Thu, 30 Jul 2026 11:06:58 +0200
| Newsgroups | org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 30 Jul 2026 12:29:34 +0400 Giorgi Tchankvetadze <[email protected]> wrote: > From: Giorgi Tchankvetadze <[email protected]> > > The veml3328_scale_vals array is declared as a flattened [4][8] array, > so accessing a scale value requires calculating the offset of its > (val, val2) pair using gain_inx * 2. > > Reshape the array as [4][4][2], with separate dimensions for integration > time, gain and the scale value pair. This removes the manual stride > calculation and makes the relationship between the indexes and values > explicit. > > Suggested-by: David Lechner <[email protected]> > Signed-off-by: Giorgi Tchankvetadze <[email protected]> > --- Okay, this is better than my original implementation. No idea what I was doing... Reviewed-by: Joshua Crofts <[email protected]> Thanks for improving my driver! > /* integration times in microseconds */ > @@ -184,9 +204,8 @@ static int veml3328_read_raw(struct iio_dev *indio_dev, > if (it_inx >= ARRAY_SIZE(veml3328_it_times) || gain_inx >= 4) > return -EINVAL; > > - /* Stride by 2 through the flattened array to match (val, val2) */ > - *val = veml3328_scale_vals[it_inx][gain_inx * 2]; > - *val2 = veml3328_scale_vals[it_inx][gain_inx * 2 + 1]; > + *val = veml3328_scale_vals[it_inx][gain_inx][0]; > + *val2 = veml3328_scale_vals[it_inx][gain_inx][1]; > > return IIO_VAL_INT_PLUS_MICRO; > > @@ -282,8 +301,8 @@ static int veml3328_write_raw(struct iio_dev *indio_dev, > return -EINVAL; > > for (i = 0; i < 4; i++) { Given how annoying hard-coded values are, could you change the `i < 4` to `i < ARRAY_SIZE(veml3328_scale_vals[it_inx])`? This should also be done for the subsequent -EINVAL check as well. Feel free to do a separate patch. > - if (val == veml3328_scale_vals[it_inx][i * 2] && > - val2 == veml3328_scale_vals[it_inx][i * 2 + 1]) > + if (val == veml3328_scale_vals[it_inx][i][0] && > + val2 == veml3328_scale_vals[it_inx][i][1]) > break; > } > -- Kind regards, Joshua Crofts