From: Jonathan Cameron <jic23@kernel.org>
To: nattan <nattanferreira58@gmail.com>
Cc: subhajit.ghosh@tweaklogic.com, lucasantonio.santos@usp.br,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v4] iio: light: apds9306: Refactor threshold get/set functions to use helper
Date: Sat, 14 Jun 2025 12:44:01 +0100 [thread overview]
Message-ID: <20250614124401.32b17eda@jic23-huawei> (raw)
In-Reply-To: <20250611174253.16578-1-nattanferreira58@gmail.com>
On Wed, 11 Jun 2025 14:42:53 -0300
nattan <nattanferreira58@gmail.com> wrote:
> From: Nattan Ferreira <nattanferreira58@gmail.com>
>
> Refactor the apds9306_event_thresh_get and apds9306_event_thresh_set
Applied with () added after function names in this description.
Thanks,
J
> functions to use a helper function (apds9306_get_thresh_reg) for
> obtaining the correct register based on the direction of the event. This
> improves code readability and maintains consistency in accessing
> threshold registers.
>
> Signed-off-by: Nattan Ferreira <nattanferreira58@gmail.com>
> Co-developed-by: Lucas Antonio <lucasantonio.santos@usp.br>
> Signed-off-by: Lucas Antonio <lucasantonio.santos@usp.br>
>
> ---
>
> Changes in v4:
> - Noted that the change actually adds four more lines to the driver file,
> so rephrased description to avoid claiming code line reduction.
> ---
> drivers/iio/light/apds9306.c | 36 ++++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
> index 69a0d609c..9216d4974 100644
> --- a/drivers/iio/light/apds9306.c
> +++ b/drivers/iio/light/apds9306.c
> @@ -744,20 +744,27 @@ static int apds9306_event_period_set(struct apds9306_data *data, int val)
> return regmap_field_write(rf->int_persist_val, val);
> }
>
> -static int apds9306_event_thresh_get(struct apds9306_data *data, int dir,
> - int *val)
> +static int apds9306_get_thresh_reg(int dir)
> {
> - int var, ret;
> - u8 buff[3];
> -
> if (dir == IIO_EV_DIR_RISING)
> - var = APDS9306_ALS_THRES_UP_0_REG;
> + return APDS9306_ALS_THRES_UP_0_REG;
> else if (dir == IIO_EV_DIR_FALLING)
> - var = APDS9306_ALS_THRES_LOW_0_REG;
> + return APDS9306_ALS_THRES_LOW_0_REG;
> else
> return -EINVAL;
> +}
> +
> +static int apds9306_event_thresh_get(struct apds9306_data *data, int dir,
> + int *val)
> +{
> + int reg, ret;
> + u8 buff[3];
>
> - ret = regmap_bulk_read(data->regmap, var, buff, sizeof(buff));
> + reg = apds9306_get_thresh_reg(dir);
> + if (reg < 0)
> + return reg;
> +
> + ret = regmap_bulk_read(data->regmap, reg, buff, sizeof(buff));
> if (ret)
> return ret;
>
> @@ -769,22 +776,19 @@ static int apds9306_event_thresh_get(struct apds9306_data *data, int dir,
> static int apds9306_event_thresh_set(struct apds9306_data *data, int dir,
> int val)
> {
> - int var;
> + int reg;
> u8 buff[3];
>
> - if (dir == IIO_EV_DIR_RISING)
> - var = APDS9306_ALS_THRES_UP_0_REG;
> - else if (dir == IIO_EV_DIR_FALLING)
> - var = APDS9306_ALS_THRES_LOW_0_REG;
> - else
> - return -EINVAL;
> + reg = apds9306_get_thresh_reg(dir);
> + if (reg < 0)
> + return reg;
>
> if (!in_range(val, 0, APDS9306_ALS_THRES_VAL_MAX))
> return -EINVAL;
>
> put_unaligned_le24(val, buff);
>
> - return regmap_bulk_write(data->regmap, var, buff, sizeof(buff));
> + return regmap_bulk_write(data->regmap, reg, buff, sizeof(buff));
> }
>
> static int apds9306_event_thresh_adaptive_get(struct apds9306_data *data, int *val)
prev parent reply other threads:[~2025-06-14 11:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 17:42 [PATCH v4] iio: light: apds9306: Refactor threshold get/set functions to use helper nattan
2025-06-14 11:44 ` Jonathan Cameron [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=20250614124401.32b17eda@jic23-huawei \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=lucasantonio.santos@usp.br \
--cc=nattanferreira58@gmail.com \
--cc=subhajit.ghosh@tweaklogic.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