Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: Gwendal Grignou <gwendal@chromium.org>,
	campello@chromium.org, jic23@kernel.org, lars@metafoo.de
Cc: linux-iio@vger.kernel.org, Gwendal Grignou <gwendal@chromium.org>
Subject: Re: [PATCH v3] iio: sx9310: Support ACPI property
Date: Fri, 12 Feb 2021 15:41:48 -0800
Message-ID: <161317330808.1254594.17984303595904501880@swboyd.mtv.corp.google.com> (raw)
In-Reply-To: <20210212214033.1304840-1-gwendal@chromium.org>

Quoting Gwendal Grignou (2021-02-12 13:40:33)
> Use device_property_read_... to support both device tree and ACPI
> bindings.
> Given |semtech,combined-sensors| is a variable array, use
> device_property_count to get the length of the array first before
> reading it to avoid underflow errors.
> 
> Add support for variable array per documentation
> ("iio/proximity/semtech,sx9310.yaml").
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> Reviewed-by: Stephen Boyd <swboyd@chromium.org>

It's attempting to fix a bug. Please add 

Fixes: 5b19ca2c78a0 ("iio: sx9310: Set various settings from DT")

> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index 6a04959df35e5..6440d12773c64 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -1215,31 +1216,42 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev)
>  }
>  
>  static const struct sx9310_reg_default *
> -sx9310_get_default_reg(struct sx9310_data *data, int i,
> +sx9310_get_default_reg(struct device *dev, int i,
>                        struct sx9310_reg_default *reg_def)
>  {
> -       int ret;
> -       const struct device_node *np = data->client->dev.of_node;
> +       int ret, count;
>         u32 combined[SX9310_NUM_CHANNELS] = { 4, 4, 4, 4 };
>         unsigned long comb_mask = 0;
>         const char *res;
>         u32 start = 0, raw = 0, pos = 0;
>  
>         memcpy(reg_def, &sx9310_default_regs[i], sizeof(*reg_def));
> -       if (!np)
> -               return reg_def;
> -
>         switch (reg_def->reg) {
>         case SX9310_REG_PROX_CTRL2:
> -               if (of_property_read_bool(np, "semtech,cs0-ground")) {
> +               if (device_property_read_bool(dev, "semtech,cs0-ground")) {
>                         reg_def->def &= ~SX9310_REG_PROX_CTRL2_SHIELDEN_MASK;
>                         reg_def->def |= SX9310_REG_PROX_CTRL2_SHIELDEN_GROUND;
>                 }
>  
>                 reg_def->def &= ~SX9310_REG_PROX_CTRL2_COMBMODE_MASK;

This should move after the parsing of the property, and only be done if
the semtech,combined-sensors property is present and valid.

> -               of_property_read_u32_array(np, "semtech,combined-sensors",
> -                                          combined, ARRAY_SIZE(combined));
> -               for (i = 0; i < ARRAY_SIZE(combined); i++) {
> +               count = device_property_count_u32(dev, "semtech,combined-sensors");
> +               if (count > 0 && count <= ARRAY_SIZE(combined))
> +                       ret = device_property_read_u32_array(dev,
> +                                       "semtech,combined-sensors", combined,
> +                                       count);
> +               else
> +                       ret = -EINVAL;
> +               if (ret) {
> +                       /*
> +                        * Either the property does not exist in the DT, the
> +                        * number of entries is incorrect, or we could not read
> +                        * the array (invalid DT).
> +                        * In all cases, use the default from the diver.
> +                        */
> +                       count = ARRAY_SIZE(combined);
> +               }
> +
> +               for (i = 0; i < count; i++) {
>                         if (combined[i] <= SX9310_NUM_CHANNELS)
>                                 comb_mask |= BIT(combined[i]);

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 21:40 Gwendal Grignou
2021-02-12 23:41 ` Stephen Boyd [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=161317330808.1254594.17984303595904501880@swboyd.mtv.corp.google.com \
    --to=swboyd@chromium.org \
    --cc=campello@chromium.org \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /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

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git