public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: LucasRabaquim <lucas.rabaquim@usp.br>,
	jic23@kernel.org, nuno.sa@analog.com, andy@kernel.org
Cc: Matheus Feitosa <matheus.feitosa@usp.br>, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: light: tsl2591: reduce code duplication in tsl2591_persist_* functions
Date: Sat, 18 Apr 2026 16:21:27 -0500	[thread overview]
Message-ID: <363f9a39-e535-42ba-ab5d-faaf9920a8ae@baylibre.com> (raw)
In-Reply-To: <20260418185422.166542-1-lucas.rabaquim@usp.br>

On 4/18/26 1:54 PM, LucasRabaquim wrote:
> Add tsl2591_persist_table as a bidirectional lookup table for
> tsl2591_persist_cycle_to_lit and tsl2591_persist_lit_to_cycle functions
> 
> These functions were prone to errors in the case of adding or updating
> TSL2591_PRST_ALS_INT_CYCLE_* values. The functions utilize a for-loop

Isn't the new table also prone to errors? Neither is very complicated.

Seems like the advantage is rather the reduction in verbosity.

> like in the function tsl2591_als_time_to_fval, allowing it to compare
> the cycle value with tsl2591_persist_table[i].cycle and return lit
> value with tsl2591_persist_table[i].lit as defined in the new type
> tsl2591_persist_entry, reducing the risk of logic mismatches.
> 
> Signed-off-by: LucasRabaquim <lucas.rabaquim@usp.br>
> Co-developed-by: Matheus Feitosa <matheus.feitosa@usp.br>
> Signed-off-by: Matheus Feitosa <matheus.feitosa@usp.br>
> ---
>  drivers/iio/light/tsl2591.c | 104 +++++++++++++-----------------------
>  1 file changed, 38 insertions(+), 66 deletions(-)
> 
> diff --git a/drivers/iio/light/tsl2591.c b/drivers/iio/light/tsl2591.c
> index c5557867ea43..86483f0b2e01 100644
> --- a/drivers/iio/light/tsl2591.c
> +++ b/drivers/iio/light/tsl2591.c
> @@ -170,6 +170,12 @@ struct tsl2591_chip {
>  	bool events_enabled;
>  };
>  
> +/* Persist cycle conversion table mapping register cycles to lit values */
> +struct tsl2591_persist_entry {
> +	u8 cycle;
> +	int lit;

Why not u8 for both?

> +};
> +

      reply	other threads:[~2026-04-18 21:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-18 18:54 [PATCH] iio: light: tsl2591: reduce code duplication in tsl2591_persist_* functions LucasRabaquim
2026-04-18 21:21 ` David Lechner [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=363f9a39-e535-42ba-ab5d-faaf9920a8ae@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=andy@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=lucas.rabaquim@usp.br \
    --cc=matheus.feitosa@usp.br \
    --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