diff mbox

[v4,13/13] iio: adc: axp20x_adc: remove !! in favor of ternary condition

Message ID 9ec180ff4358ac6e163115aa7832a0674b6a640e.1519044068.git-series.quentin.schulz@bootlin.com (mailing list archive)
State New, archived
Headers show

Commit Message

Quentin Schulz Feb. 19, 2018, 12:47 p.m. UTC
!!'s behaviour isn't that obvious and sparse complained about it, so
let's replace it with a ternary condition.

Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
---
 drivers/iio/adc/axp20x_adc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Jonathan Cameron Feb. 24, 2018, 12:20 p.m. UTC | #1
On Mon, 19 Feb 2018 13:47:36 +0100
Quentin Schulz <quentin.schulz@bootlin.com> wrote:

> !!'s behaviour isn't that obvious and sparse complained about it, so
> let's replace it with a ternary condition.
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/axp20x_adc.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c
> index a30a972..7a745cf 100644
> --- a/drivers/iio/adc/axp20x_adc.c
> +++ b/drivers/iio/adc/axp20x_adc.c
> @@ -365,7 +365,7 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel,
>  		return -EINVAL;
>  	}
>  
> -	*val = !!(*val) * 700000;
> +	*val = *val ? 700000 : 0;
>  
>  	return IIO_VAL_INT;
>  }
> @@ -442,15 +442,17 @@ static int axp20x_write_raw(struct iio_dev *indio_dev,
>  	if (val != 0 && val != 700000)
>  		return -EINVAL;
>  
> +	val = val ? 1 : 0;
> +
>  	switch (chan->channel) {
>  	case AXP20X_GPIO0_V:
>  		reg = AXP20X_GPIO10_IN_RANGE_GPIO0;
> -		regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(!!val);
> +		regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(val);
>  		break;
>  
>  	case AXP20X_GPIO1_V:
>  		reg = AXP20X_GPIO10_IN_RANGE_GPIO1;
> -		regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(!!val);
> +		regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(val);
>  		break;
>  
>  	default:

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c
index a30a972..7a745cf 100644
--- a/drivers/iio/adc/axp20x_adc.c
+++ b/drivers/iio/adc/axp20x_adc.c
@@ -365,7 +365,7 @@  static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel,
 		return -EINVAL;
 	}
 
-	*val = !!(*val) * 700000;
+	*val = *val ? 700000 : 0;
 
 	return IIO_VAL_INT;
 }
@@ -442,15 +442,17 @@  static int axp20x_write_raw(struct iio_dev *indio_dev,
 	if (val != 0 && val != 700000)
 		return -EINVAL;
 
+	val = val ? 1 : 0;
+
 	switch (chan->channel) {
 	case AXP20X_GPIO0_V:
 		reg = AXP20X_GPIO10_IN_RANGE_GPIO0;
-		regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(!!val);
+		regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(val);
 		break;
 
 	case AXP20X_GPIO1_V:
 		reg = AXP20X_GPIO10_IN_RANGE_GPIO1;
-		regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(!!val);
+		regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(val);
 		break;
 
 	default: