All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Bhumika Goyal <bhumirks@gmail.com>, outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] Re: [PATCH] Staging: rtl8192e: Remove ternary operator
Date: Sun, 9 Oct 2016 16:46:36 +0200	[thread overview]
Message-ID: <20161009144636.GA11833@kroah.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1610091635130.3462@hadrien>

On Sun, Oct 09, 2016 at 04:36:34PM +0200, Julia Lawall wrote:
> 
> 
> On Sun, 9 Oct 2016, Greg KH wrote:
> 
> > On Sat, Oct 08, 2016 at 11:58:17PM +0530, Bhumika Goyal wrote:
> > > Relational and logical operators evaluate to either true or false.
> > > Explicit conversion is not needed so remove the ternary operator.
> > > Done using coccinelle:
> > >
> > > @r@
> > > expression A,B;
> > > symbol true,false;
> > > binary operator b = {==,!=,&&,||,>=,<=,>,<};
> > > @@
> > > - (A b B) ? true : false
> > > + A b B
> > >
> > > Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
> > > ---
> > >  drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
> > >  drivers/staging/rtl8192e/rtllib.h         |  2 +-
> > >  2 files changed, 5 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/staging/rtl8192e/rtl819x_HTProc.c b/drivers/staging/rtl8192e/rtl819x_HTProc.c
> > > index dd9c0c8..8cd51a9 100644
> > > --- a/drivers/staging/rtl8192e/rtl819x_HTProc.c
> > > +++ b/drivers/staging/rtl8192e/rtl819x_HTProc.c
> > > @@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
> > >  #endif
> > >  	HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
> > >  			  (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
> > > -	pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
> > > -				 true : false);
> > > +	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);
> >
> > Ugh, I _hate_ ? : statements.
> >
> > Just write the thing out, is this easy to read as is?
> >
> > >  	pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
> > > -				    ((pPeerHTCap->ShortGI20Mhz == 1) ?
> > > -				    true : false) : false);
> > > +				    (pPeerHTCap->ShortGI20Mhz == 1) : false);
> > >  	pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
> > > -				     ((pPeerHTCap->ShortGI40Mhz == 1) ?
> > > -				     true : false) : false);
> > > +				     (pPeerHTCap->ShortGI40Mhz == 1) : false);
> >
> > Is this?  Kernel code is meant to be read by humans first, and the
> > compiler second.  None of this will be any different if you write out a
> > if () statement.  Please just do that instead.
> 
> Wouldn't && or || be nicer if possible?  If the == 1 are actually testing
> booleans, it could be quite concise.

Yes, maybe, but never ? : if at all possible (as function arguments it
makes sense.)

thanks,

greg k-h


  reply	other threads:[~2016-10-09 14:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-08 18:28 [PATCH] Staging: rtl8192e: Remove ternary operator Bhumika Goyal
2016-10-09  6:00 ` [Outreachy kernel] " Julia Lawall
2016-10-09  6:38   ` Bhumika Goyal
2016-10-09 10:51     ` Julia Lawall
2016-10-09 14:26 ` Greg KH
2016-10-09 14:36   ` [Outreachy kernel] " Julia Lawall
2016-10-09 14:46     ` Greg KH [this message]
2016-10-09 16:21       ` Bhumika Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161009144636.GA11833@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=bhumirks@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=outreachy-kernel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.