Re: [PATCH 1/7] iio: light: bh1745: simplify code in write_event_config callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 24 Oct 2024 11:11:23 +0200
Julien Stephan <jstephan@xxxxxxxxxxxx> wrote:

> iio_ev_state_store is actually using kstrtobool to check user
> input, then gives the converted boolean value to the write_event_config
> callback.
> 
> Remove useless code in write_event_config callback.
> 
> Signed-off-by: Julien Stephan <jstephan@xxxxxxxxxxxx>
There are a few additions needed to the final patch. 
I'll pick up the earlier ones now though.

Applied this one.

> ---
>  drivers/iio/light/bh1745.c | 48 +++++++++++++++++++++-------------------------
>  1 file changed, 22 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/iio/light/bh1745.c b/drivers/iio/light/bh1745.c
> index 2e458e9d5d85308fb6a13d9dbd845fa03b56a40e..fc6bf062d4f510886f909509d8115f0cf892f3c4 100644
> --- a/drivers/iio/light/bh1745.c
> +++ b/drivers/iio/light/bh1745.c
> @@ -643,41 +643,37 @@ static int bh1745_write_event_config(struct iio_dev *indio_dev,
>  	struct bh1745_data *data = iio_priv(indio_dev);
>  	int value;
>  
> -	if (state == 0)
> +	if (!state)
>  		return regmap_clear_bits(data->regmap,
>  					 BH1745_INTR, BH1745_INTR_ENABLE);
>  
> -	if (state == 1) {
> -		/* Latch is always enabled when enabling interrupt */
> -		value = BH1745_INTR_ENABLE;
> +	/* Latch is always enabled when enabling interrupt */
> +	value = BH1745_INTR_ENABLE;
>  
> -		switch (chan->channel2) {
> -		case IIO_MOD_LIGHT_RED:
> -			return regmap_write(data->regmap, BH1745_INTR,
> -					    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> -							       BH1745_INTR_SOURCE_RED));
> +	switch (chan->channel2) {
> +	case IIO_MOD_LIGHT_RED:
> +		return regmap_write(data->regmap, BH1745_INTR,
> +				    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> +						       BH1745_INTR_SOURCE_RED));
>  
> -		case IIO_MOD_LIGHT_GREEN:
> -			return regmap_write(data->regmap, BH1745_INTR,
> -					    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> -							       BH1745_INTR_SOURCE_GREEN));
> +	case IIO_MOD_LIGHT_GREEN:
> +		return regmap_write(data->regmap, BH1745_INTR,
> +				    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> +						       BH1745_INTR_SOURCE_GREEN));
>  
> -		case IIO_MOD_LIGHT_BLUE:
> -			return regmap_write(data->regmap, BH1745_INTR,
> -					    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> -							       BH1745_INTR_SOURCE_BLUE));
> +	case IIO_MOD_LIGHT_BLUE:
> +		return regmap_write(data->regmap, BH1745_INTR,
> +				    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> +						       BH1745_INTR_SOURCE_BLUE));
>  
> -		case IIO_MOD_LIGHT_CLEAR:
> -			return regmap_write(data->regmap, BH1745_INTR,
> -					    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> -							       BH1745_INTR_SOURCE_CLEAR));
> +	case IIO_MOD_LIGHT_CLEAR:
> +		return regmap_write(data->regmap, BH1745_INTR,
> +				    value | FIELD_PREP(BH1745_INTR_SOURCE_MASK,
> +						       BH1745_INTR_SOURCE_CLEAR));
>  
> -		default:
> -			return -EINVAL;
> -		}
> +	default:
> +		return -EINVAL;
>  	}
> -
> -	return -EINVAL;
>  }
>  
>  static int bh1745_read_avail(struct iio_dev *indio_dev,
> 





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux