All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Mathieu Othacehe <m.othacehe@gmail.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 3/4] iio: vcnl4000: Add sampling frequency support for VCNL4010/20.
Date: Sat, 25 Apr 2020 16:52:23 +0100	[thread overview]
Message-ID: <20200425165223.0fc0e930@archlinux> (raw)
In-Reply-To: <CAHp75VcJ300S8r_f2cueYzB0OaLBJK9oJySgz5Jekb7dGFWnCw@mail.gmail.com>

On Tue, 21 Apr 2020 15:22:11 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Tue, Apr 21, 2020 at 10:56 AM Mathieu Othacehe <m.othacehe@gmail.com> wrote:
> >
> > Add sampling frequency support for proximity data on VCNL4010 and VCNL4020
> > chips.  
> 
> Couple of nitpicks below.
> 
> ...
> 
> > +static const int vcnl4010_prox_sampling_frequency[][2] = {
> > +       {1, 950000},
> > +       {3, 906250},
> > +       {7, 812500},
> > +       {16, 625000},
> > +       {31, 250000},
> > +       {62, 500000},
> > +       {125, 0},  
> 
> > +       {250, 0}  
> 
> Leave comma here, potentially helpful if it will be extended.

Hi Andy,

Doesn't particularly matter either way, but given this is a list of the values
supported by the device, very unlikely it will be extended.

Games like trying to share the first part of a longer array between
multiple device types might occur, but those are usually really ugly.

Jonathan

> 
> > +};  
> 
> ...
> 
> > +static int vcnl4010_write_proxy_samp_freq(struct vcnl4000_data *data, int val,
> > +                                         int val2)
> > +{
> > +       int i;
> > +       const int len = ARRAY_SIZE(vcnl4010_prox_sampling_frequency);
> > +
> > +       for (i = 0; i < len; i++) {
> > +               if (val <= vcnl4010_prox_sampling_frequency[i][0])
> > +                       break;
> > +       }
> > +
> > +       if (i == len)
> > +               return -EINVAL;  
> 
> I would refactor this
> 
>   unsigned int i = ARRAY_SIZE(vcnl4010_prox_sampling_frequency);
> 
>   do {
>     if (val > vcnl4010_prox_sampling_frequency[i][0])
>       break;
>   } while (--i);
> 
> You won't need to go full array to return error in this case.
> 
> > +       return i2c_smbus_write_byte_data(data->client, VCNL4010_PROX_RATE, i);
> > +}  
> 


  reply	other threads:[~2020-04-25 15:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21  7:55 [PATCH v4 0/4] iio: vcnl: Add interrupts support for VCNL4010/20 Mathieu Othacehe
2020-04-21  7:55 ` [PATCH v4 1/4] iio: vcnl4000: Factorize data reading and writing Mathieu Othacehe
2020-04-21  7:55 ` [PATCH v4 2/4] iio: vcnl4000: Add event support for VCNL4010/20 Mathieu Othacehe
2020-04-21 11:24   ` Andy Shevchenko
2020-04-22  8:02     ` Mathieu Othacehe
2020-04-22  8:25       ` Andy Shevchenko
2020-04-25 19:47   ` Jonathan Cameron
2020-04-21  7:55 ` [PATCH v4 3/4] iio: vcnl4000: Add sampling frequency " Mathieu Othacehe
2020-04-21 12:22   ` Andy Shevchenko
2020-04-25 15:52     ` Jonathan Cameron [this message]
2020-04-25 17:14       ` Andy Shevchenko
2020-04-25 19:49   ` Jonathan Cameron
2020-04-21  7:55 ` [PATCH v4 4/4] iio: vcnl4000: Add buffer " Mathieu Othacehe
2020-04-21 12:27   ` Andy Shevchenko
2020-04-22  8:14     ` Mathieu Othacehe
2020-04-25 16:09       ` Jonathan Cameron
2020-04-25 15:57     ` Jonathan Cameron

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=20200425165223.0fc0e930@archlinux \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.othacehe@gmail.com \
    --cc=pmeerw@pmeerw.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.