Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Ivan Mikhaylov <i.mikhaylov@yadro.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Rob Herring <robh+dt@kernel.org>
Subject: Re: [PATCH v3 2/2] iio: proximity: Add driver support for vcnl3020 proximity sensor
Date: Thu, 26 Mar 2020 22:39:13 +0200
Message-ID: <CAHp75VfL726QwyR4eJL1HCVLvyQ5W0tJfbEJ+mhmsRWHkB8=6w@mail.gmail.com> (raw)
In-Reply-To: <20200326155118.8224-3-i.mikhaylov@yadro.com>

On Thu, Mar 26, 2020 at 5:51 PM Ivan Mikhaylov <i.mikhaylov@yadro.com> wrote:
>
> Proximity sensor driver based on light/vcnl4000.c code.
> For now supports only the single on-demand measurement.
>
> The VCNL3020 is a fully integrated proximity sensor. Fully
> integrated means that the infrared emitter is included in the
> package. It has 16-bit resolution. It includes a signal
> processing IC and features standard I2C communication
> interface. It features an interrupt function.

Thank you for an update, my (only minors) comments below.
After addressing them,

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

(Don't forget to fix DTS schema as Rob's bot pointed out)

...

> +#define VCNL_ON_DEMAND_TIMEOUT 100000 /* on-demand measurement timeout in us */

This also should have _US suffix, and thus comment is not necessary.

> +#define VCNL_POLL_US           20000

...

> +       if (reg == VCNL3020_PROD_ID) {
> +               data->rev = reg;
> +               mutex_init(&data->lock);
> +       } else {
> +               dev_err(data->dev,
> +                       "Product id (%x) did not match vcnl3020 (%x)", reg,
> +                       VCNL3020_PROD_ID);
> +               return -ENODEV;
> +       }

I would recommend to use standard pattern, i.e.
  if (reg != ...) {
    ...error handling...
  }

in this case else branch becomes a mainstream code in the function.

...

> +       rc = regmap_write(data->regmap, VCNL_LED_CURRENT, led_current);
> +       if (rc) {
> +               dev_err(data->dev, "Error (%d) setting LED current", rc);
> +       }

Now curly braces are redundant.

> +       return rc;

...

> +       rc = regmap_read(data->regmap, VCNL_PS_RESULT_HI, &reg);
> +       if (rc)
> +               goto err_unlock;

> +       *val = reg << 8;

This actually breaks the principle of not touching output buffers /
variables in case of error.

Perhaps

    unsigned int hi, lo;

instead of / along with reg?

> +       dev_dbg(data->dev, "result high byte 0x%x", rc);
> +
> +       rc = regmap_read(data->regmap, VCNL_PS_RESULT_LO, &reg);
> +       if (rc)
> +               goto err_unlock;
> +       *val |= reg;
> +       dev_dbg(data->dev, "result low byte 0x%x", rc);

-- 
With Best Regards,
Andy Shevchenko

      reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26 15:51 [PATCH v3 0/2] iio: proximity: driver for vcnl3020 Ivan Mikhaylov
2020-03-26 15:51 ` [PATCH v3 1/2] iio: proximity: provide device tree binding document Ivan Mikhaylov
2020-03-26 15:51 ` [PATCH v3 2/2] iio: proximity: Add driver support for vcnl3020 proximity sensor Ivan Mikhaylov
2020-03-26 20:39   ` Andy Shevchenko [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='CAHp75VfL726QwyR4eJL1HCVLvyQ5W0tJfbEJ+mhmsRWHkB8=6w@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=i.mikhaylov@yadro.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@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