linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool
@ 2016-07-01 14:33 Andrew F. Davis
  2016-07-01 15:03 ` Peter Meerwald-Stadler
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew F. Davis @ 2016-07-01 14:33 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, linux-kernel, Andrew F . Davis

Found with scripts/coccinelle/misc/boolconv.cocci.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 drivers/iio/dac/mcp4725.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index cca935c..c3bb3fd 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -361,7 +361,7 @@ static int mcp4725_probe(struct i2c_client *client,
 		return err;
 	}
 	pd = (inbuf[0] >> 1) & 0x3;
-	data->powerdown = pd > 0 ? true : false;
+	data->powerdown = pd > 0;
 	data->powerdown_mode = pd ? pd - 1 : 2; /* largest register to gnd */
 	data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
 
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool
  2016-07-01 14:33 [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool Andrew F. Davis
@ 2016-07-01 15:03 ` Peter Meerwald-Stadler
  2016-07-01 15:18   ` Andrew F. Davis
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Meerwald-Stadler @ 2016-07-01 15:03 UTC (permalink / raw)
  To: Andrew F. Davis; +Cc: Jonathan Cameron, linux-iio, linux-kernel


> Found with scripts/coccinelle/misc/boolconv.cocci.

I'd argue that

        pd = (inbuf[0] >> 1) & 0x3;
        if (pd) {
                data->powerdown = true;
                data->powerdown_mode = pd - 1;
        } else {
                data->powerdown = false;
                data->powerdown_mode = 2; /* largest register to gnd */
        }

is less compact but probably easier to read/understand;

> Signed-off-by: Andrew F. Davis <afd@ti.com>

but I'm fine with the proposed patch as well to make cocci happy

regards, p.

> ---
>  drivers/iio/dac/mcp4725.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
> index cca935c..c3bb3fd 100644
> --- a/drivers/iio/dac/mcp4725.c
> +++ b/drivers/iio/dac/mcp4725.c
> @@ -361,7 +361,7 @@ static int mcp4725_probe(struct i2c_client *client,
>  		return err;
>  	}
>  	pd = (inbuf[0] >> 1) & 0x3;
> -	data->powerdown = pd > 0 ? true : false;
> +	data->powerdown = pd > 0;
>  	data->powerdown_mode = pd ? pd - 1 : 2; /* largest register to gnd */
>  	data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
>  
> 

-- 

Peter Meerwald-Stadler
+43-664-2444418 (mobile)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool
  2016-07-01 15:03 ` Peter Meerwald-Stadler
@ 2016-07-01 15:18   ` Andrew F. Davis
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew F. Davis @ 2016-07-01 15:18 UTC (permalink / raw)
  To: Peter Meerwald-Stadler; +Cc: Jonathan Cameron, linux-iio, linux-kernel

On 07/01/2016 10:03 AM, Peter Meerwald-Stadler wrote:
> 
>> Found with scripts/coccinelle/misc/boolconv.cocci.
> 
> I'd argue that
> 
>         pd = (inbuf[0] >> 1) & 0x3;
>         if (pd) {
>                 data->powerdown = true;
>                 data->powerdown_mode = pd - 1;
>         } else {
>                 data->powerdown = false;
>                 data->powerdown_mode = 2; /* largest register to gnd */
>         }
> 
> is less compact but probably easier to read/understand;
> 

I agree, this is a much better fix. Would you like to submit this
version as a patch?

Andrew

>> Signed-off-by: Andrew F. Davis <afd@ti.com>
> 
> but I'm fine with the proposed patch as well to make cocci happy
> 
> regards, p.
> 
>> ---
>>  drivers/iio/dac/mcp4725.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
>> index cca935c..c3bb3fd 100644
>> --- a/drivers/iio/dac/mcp4725.c
>> +++ b/drivers/iio/dac/mcp4725.c
>> @@ -361,7 +361,7 @@ static int mcp4725_probe(struct i2c_client *client,
>>  		return err;
>>  	}
>>  	pd = (inbuf[0] >> 1) & 0x3;
>> -	data->powerdown = pd > 0 ? true : false;
>> +	data->powerdown = pd > 0;
>>  	data->powerdown_mode = pd ? pd - 1 : 2; /* largest register to gnd */
>>  	data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
>>  
>>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool
@ 2017-12-05 19:12 Andrew F. Davis
  2017-12-10 18:32 ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew F. Davis @ 2017-12-05 19:12 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: linux-iio, Andrew F . Davis

Found with scripts/coccinelle/misc/boolconv.cocci.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 drivers/iio/dac/mcp4725.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index afa856d10c26..8b5aad4c32d9 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -476,7 +476,7 @@ static int mcp4725_probe(struct i2c_client *client,
 		goto err_disable_vref_reg;
 	}
 	pd = (inbuf[0] >> 1) & 0x3;
-	data->powerdown = pd > 0 ? true : false;
+	data->powerdown = pd > 0;
 	data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */
 	data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
 	if (data->id == MCP4726)
-- 
2.15.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool
  2017-12-05 19:12 Andrew F. Davis
@ 2017-12-10 18:32 ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2017-12-10 18:32 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-iio

On Tue, 5 Dec 2017 13:12:01 -0600
"Andrew F. Davis" <afd@ti.com> wrote:

> Found with scripts/coccinelle/misc/boolconv.cocci.
> 
> Signed-off-by: Andrew F. Davis <afd@ti.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/dac/mcp4725.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
> index afa856d10c26..8b5aad4c32d9 100644
> --- a/drivers/iio/dac/mcp4725.c
> +++ b/drivers/iio/dac/mcp4725.c
> @@ -476,7 +476,7 @@ static int mcp4725_probe(struct i2c_client *client,
>  		goto err_disable_vref_reg;
>  	}
>  	pd = (inbuf[0] >> 1) & 0x3;
> -	data->powerdown = pd > 0 ? true : false;
> +	data->powerdown = pd > 0;
>  	data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */
>  	data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
>  	if (data->id == MCP4726)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-10 18:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-01 14:33 [PATCH] iio: dac: mcp4725: Remove unneeded conversions to bool Andrew F. Davis
2016-07-01 15:03 ` Peter Meerwald-Stadler
2016-07-01 15:18   ` Andrew F. Davis
  -- strict thread matches above, loose matches on Subject: below --
2017-12-05 19:12 Andrew F. Davis
2017-12-10 18:32 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).