From: Joshua Crofts <joshua.crofts1@gmail.com>
To: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Giorgi Tchankvetadze <giorgi@tchankvetadze.com>
Subject: Re: [PATCH v2] iio: light: veml3328: reshape scale array for readability
Date: Thu, 30 Jul 2026 11:06:58 +0200 [thread overview]
Message-ID: <20260730110658.0000759a@gmail.com> (raw)
In-Reply-To: <20260730082932.79484-3-giorgitchankvetadze1997@gmail.com>
On Thu, 30 Jul 2026 12:29:34 +0400
Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com> wrote:
> From: Giorgi Tchankvetadze <giorgi@tchankvetadze.com>
>
> 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 <dlechner@baylibre.com>
> Signed-off-by: Giorgi Tchankvetadze <giorgi@tchankvetadze.com>
> ---
Okay, this is better than my original implementation. No idea what I was
doing...
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
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
prev parent reply other threads:[~2026-07-30 9:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 8:29 [PATCH v2] iio: light: veml3328: reshape scale array for readability Giorgi Tchankvetadze
2026-07-30 9:06 ` Joshua Crofts [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260730110658.0000759a@gmail.com \
--to=joshua.crofts1@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=giorgi@tchankvetadze.com \
--cc=giorgitchankvetadze1997@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox