linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: iio: ad7150: use ternary operating to ensure 0/1 value
@ 2019-06-14 16:50 Melissa Wen
  2019-06-16 10:15 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Melissa Wen @ 2019-06-14 16:50 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Stefan Popa,
	Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Greg Kroah-Hartman, Barry Song
  Cc: linux-iio, devel, linux-kernel, kernel-usp

Remove idiom and use ternary operator for consistently trigger 0/1 value
on variable declaration.

Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
---
 drivers/staging/iio/cdc/ad7150.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
index 8234da4b8c65..25598bf124fb 100644
--- a/drivers/staging/iio/cdc/ad7150.c
+++ b/drivers/staging/iio/cdc/ad7150.c
@@ -350,8 +350,8 @@ static ssize_t ad7150_show_timeout(struct device *dev,
 
 	/* use the event code for consistency reasons */
 	int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
-	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address)
-			== IIO_EV_DIR_RISING);
+	int rising = (IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address)
+		      == IIO_EV_DIR_RISING) ? 1 : 0;
 
 	switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) {
 	case IIO_EV_TYPE_MAG_ADAPTIVE:
-- 
2.20.1


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

* Re: [PATCH] staging: iio: ad7150: use ternary operating to ensure 0/1 value
  2019-06-14 16:50 [PATCH] staging: iio: ad7150: use ternary operating to ensure 0/1 value Melissa Wen
@ 2019-06-16 10:15 ` Jonathan Cameron
  2019-06-17  8:40   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2019-06-16 10:15 UTC (permalink / raw)
  To: Melissa Wen
  Cc: Lars-Peter Clausen, Michael Hennerich, Stefan Popa,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman,
	Barry Song, linux-iio, devel, linux-kernel, kernel-usp

On Fri, 14 Jun 2019 13:50:59 -0300
Melissa Wen <melissa.srw@gmail.com> wrote:

> Remove idiom and use ternary operator for consistently trigger 0/1 value
> on variable declaration.
> 
> Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
Hi Melissa,

In general I would consider this unnecessary churn as, whilst
it's no longer a favoured idiom, it is extremely common in the
kernel.  However, as this is a staging cleanup, fair enough to
make it as 'nice as possible'! 

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/cdc/ad7150.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
> index 8234da4b8c65..25598bf124fb 100644
> --- a/drivers/staging/iio/cdc/ad7150.c
> +++ b/drivers/staging/iio/cdc/ad7150.c
> @@ -350,8 +350,8 @@ static ssize_t ad7150_show_timeout(struct device *dev,
>  
>  	/* use the event code for consistency reasons */
>  	int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
> -	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address)
> -			== IIO_EV_DIR_RISING);
> +	int rising = (IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address)
> +		      == IIO_EV_DIR_RISING) ? 1 : 0;
>  
>  	switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) {
>  	case IIO_EV_TYPE_MAG_ADAPTIVE:


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

* Re: [PATCH] staging: iio: ad7150: use ternary operating to ensure 0/1 value
  2019-06-16 10:15 ` Jonathan Cameron
@ 2019-06-17  8:40   ` Dan Carpenter
  2019-06-22 10:58     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2019-06-17  8:40 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Melissa Wen, devel, Lars-Peter Clausen, Stefan Popa,
	Michael Hennerich, linux-iio, Greg Kroah-Hartman, Barry Song,
	linux-kernel, kernel-usp, Peter Meerwald-Stadler, Hartmut Knaack

On Sun, Jun 16, 2019 at 11:15:16AM +0100, Jonathan Cameron wrote:
> On Fri, 14 Jun 2019 13:50:59 -0300
> Melissa Wen <melissa.srw@gmail.com> wrote:
> 
> > Remove idiom and use ternary operator for consistently trigger 0/1 value
> > on variable declaration.
> > 
> > Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
> Hi Melissa,
> 
> In general I would consider this unnecessary churn as, whilst
> it's no longer a favoured idiom, it is extremely common in the
> kernel.

It's still my favourite...  Why wouldn't people like it?  It feels like
last week I just saw someone send a bunch of:

-	foo = (bar == baz) ? 1 : 0;
+	foo = (bar == baz);

patches and I thought it was an improvement at the time...

regards,
dan carpenter


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

* Re: [PATCH] staging: iio: ad7150: use ternary operating to ensure 0/1 value
  2019-06-17  8:40   ` Dan Carpenter
@ 2019-06-22 10:58     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2019-06-22 10:58 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Melissa Wen, devel, Lars-Peter Clausen, Stefan Popa,
	Michael Hennerich, linux-iio, Greg Kroah-Hartman, Barry Song,
	linux-kernel, kernel-usp, Peter Meerwald-Stadler, Hartmut Knaack

On Mon, 17 Jun 2019 11:40:34 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> On Sun, Jun 16, 2019 at 11:15:16AM +0100, Jonathan Cameron wrote:
> > On Fri, 14 Jun 2019 13:50:59 -0300
> > Melissa Wen <melissa.srw@gmail.com> wrote:
> >   
> > > Remove idiom and use ternary operator for consistently trigger 0/1 value
> > > on variable declaration.
> > > 
> > > Signed-off-by: Melissa Wen <melissa.srw@gmail.com>  
> > Hi Melissa,
> > 
> > In general I would consider this unnecessary churn as, whilst
> > it's no longer a favoured idiom, it is extremely common in the
> > kernel.  
> 
> It's still my favourite...  Why wouldn't people like it?  It feels like
> last week I just saw someone send a bunch of:
> 
> -	foo = (bar == baz) ? 1 : 0;
> +	foo = (bar == baz);
> 
> patches and I thought it was an improvement at the time...

That one is nice enough, it's the !! that Linus came out fairly
strongly against though not sure I can find the particular email. 
That one is a fairly kernel specific idiom that I'll be honest I've
rarely seen elsewhere ;)  I remember wincing at the thread
on this as it was an idiom I personally rather liked.

In cases where it doesn't matter because foo doesn't need to 1 or
0 then what you have is nice and clean.

I can't say it's one I care that much about, but I am happy if code
that happens to be under cleanup anyway has this little bit made
the 'preferred style'.  There is something to said for consistency.

Jonathan


> 
> regards,
> dan carpenter
> 


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

end of thread, other threads:[~2019-06-22 10:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14 16:50 [PATCH] staging: iio: ad7150: use ternary operating to ensure 0/1 value Melissa Wen
2019-06-16 10:15 ` Jonathan Cameron
2019-06-17  8:40   ` Dan Carpenter
2019-06-22 10:58     ` 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).