Re: [PATCH 07/15] iio: sx9310: Use long instead of int for channel bitmaps

From: Andy Shevchenko
Date: Tue Jul 28 2020 - 14:13:46 EST


On Tue, Jul 28, 2020 at 6:14 PM Daniel Campello <campello@xxxxxxxxxxxx> wrote:
>
> Uses for_each_set_bit() macro to loop over channel bitmaps.
>

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

> Signed-off-by: Daniel Campello <campello@xxxxxxxxxxxx>
> ---
>
> drivers/iio/proximity/sx9310.c | 24 +++++++++++++-----------
> 1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index fb5c16f2aa6b1a..2465064971d0a7 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -136,7 +136,8 @@ struct sx9310_data {
> /* Remember enabled channels and sample rate during suspend. */
> unsigned int suspend_ctrl0;
> struct completion completion;
> - unsigned int chan_read, chan_event;
> + unsigned long chan_read;
> + unsigned long chan_event;
> int channel_users[SX9310_NUM_CHANNELS];
> unsigned int whoami;
> };
> @@ -279,15 +280,16 @@ static const struct regmap_config sx9310_regmap_config = {
> };
>
> static int sx9310_update_chan_en(struct sx9310_data *data,
> - unsigned int chan_read,
> - unsigned int chan_event)
> + unsigned long chan_read,
> + unsigned long chan_event)
> {
> int ret;
> + unsigned long channels = chan_read | chan_event;
>
> - if ((data->chan_read | data->chan_event) != (chan_read | chan_event)) {
> + if ((data->chan_read | data->chan_event) != channels) {
> ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0,
> SX9310_REG_PROX_CTRL0_SENSOREN_MASK,
> - chan_read | chan_event);
> + channels);
> if (ret)
> return ret;
> }
> @@ -538,13 +540,13 @@ static void sx9310_push_events(struct iio_dev *indio_dev)
> return;
> }
>
> - for (chan = 0; chan < SX9310_NUM_CHANNELS; chan++) {
> + for_each_set_bit(chan, &data->chan_event, SX9310_NUM_CHANNELS) {
> int dir;
> u64 ev;
> - bool new_prox = val & BIT(chan);
> + bool new_prox;
> +
> + new_prox = val & BIT(chan);
>
> - if (!(data->chan_event & BIT(chan)))
> - continue;
> if (new_prox == data->prox_stat[chan])
> /* No change on this channel. */
> continue;
> @@ -712,13 +714,13 @@ static irqreturn_t sx9310_trigger_handler(int irq, void *private)
> static int sx9310_buffer_preenable(struct iio_dev *indio_dev)
> {
> struct sx9310_data *data = iio_priv(indio_dev);
> - unsigned int channels = 0;
> + unsigned long channels = 0;
> int bit, ret;
>
> mutex_lock(&data->mutex);
> for_each_set_bit(bit, indio_dev->active_scan_mask,
> indio_dev->masklength)
> - channels |= BIT(indio_dev->channels[bit].channel);
> + __set_bit(indio_dev->channels[bit].channel, &channels);
>
> ret = sx9310_update_chan_en(data, channels, data->chan_event);
> mutex_unlock(&data->mutex);
> --
> 2.28.0.rc0.142.g3c755180ce-goog
>


--
With Best Regards,
Andy Shevchenko