[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VcJ300S8r_f2cueYzB0OaLBJK9oJySgz5Jekb7dGFWnCw@mail.gmail.com>
Date: Tue, 21 Apr 2020 15:22:11 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Mathieu Othacehe <m.othacehe@...il.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
Hartmut Knaack <knaack.h@....de>,
Lars-Peter Clausen <lars@...afoo.de>,
Peter Meerwald <pmeerw@...erw.net>,
linux-iio <linux-iio@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 3/4] iio: vcnl4000: Add sampling frequency support for VCNL4010/20.
On Tue, Apr 21, 2020 at 10:56 AM Mathieu Othacehe <m.othacehe@...il.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.
> +};
...
> +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);
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists