public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Riccardo Lucchese <riccardo.lucchese@gmail.com>
Cc: gregkh@linuxfoundation.org, oleg.drokin@intel.com,
	devel@driverdev.osuosl.org, josh@joshtriplett.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] staging: lustre/lustre/lov: Remove unneeded 'if' statement in lov_request.c/lov_check_set()
Date: Sun, 20 Jul 2014 14:37:47 +0300	[thread overview]
Message-ID: <20140720113747.GG18338@mwanda> (raw)
In-Reply-To: <20140720110836.GC12613@rlp>

On Sun, Jul 20, 2014 at 01:08:36PM +0200, Riccardo Lucchese wrote:
> Dan,
> 
> On Sun, Jul 20, 2014 at 07:52:53AM +0300, Dan Carpenter wrote:
> > On Sat, Jul 19, 2014 at 09:34:56PM +0200, Riccardo Lucchese wrote:
> > > It is silly to go through an if statement to set a single boolean
> > > value in function of a single boolean expression. In the function
> > > lov_check_set, assign the return value directly.
> > > 
> > > Signed-off-by: Riccardo Lucchese <riccardo.lucchese@gmail.com>
> > > ---
> > >  drivers/staging/lustre/lustre/lov/lov_request.c | 11 +++++------
> > >  1 file changed, 5 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
> > > index ce830e4..90fc66a 100644
> > > --- a/drivers/staging/lustre/lustre/lov/lov_request.c
> > > +++ b/drivers/staging/lustre/lustre/lov/lov_request.c
> > > @@ -140,14 +140,13 @@ void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
> > >  
> > >  static int lov_check_set(struct lov_obd *lov, int idx)
> > >  {
> > > -	int rc = 0;
> > > +	int rc;
> > >  	mutex_lock(&lov->lov_lock);
> > >  
> > > -	if (lov->lov_tgts[idx] == NULL ||
> > > -	    lov->lov_tgts[idx]->ltd_active ||
> > > -	    (lov->lov_tgts[idx]->ltd_exp != NULL &&
> > > -	     class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried))
> > > -		rc = 1;
> > > +	rc = lov->lov_tgts[idx] == NULL ||
> > > +		lov->lov_tgts[idx]->ltd_active ||
> > > +		(lov->lov_tgts[idx]->ltd_exp != NULL &&
> > > +		 class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried);
> > 
> > I don't see how this makes the code more readable at all.
> 
> Thank you for the comment. Would you consider something like the
> following diff instead ? Otherwise, I will resend the series for
> review without this change.
> 
> riccardo
> 
> ---
> 
> diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
> index ce830e4..ae670bb 100644
> --- a/drivers/staging/lustre/lustre/lov/lov_request.c
> +++ b/drivers/staging/lustre/lustre/lov/lov_request.c
> @@ -140,14 +140,14 @@ void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
>  
>  static int lov_check_set(struct lov_obd *lov, int idx)
>  {
> -	int rc = 0;
> +	int rc;
> +	struct lov_tgt_desc *desc;
>  	mutex_lock(&lov->lov_lock);
>  
> -	if (lov->lov_tgts[idx] == NULL ||
> -	    lov->lov_tgts[idx]->ltd_active ||
> -	    (lov->lov_tgts[idx]->ltd_exp != NULL &&
> -	     class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried))
> -		rc = 1;
> +	desc = lov->lov_tgts[idx];
> +	rc = !desc || desc->ltd_active ||
> +		(desc->ltd_exp &&
> +		 class_exp2cliimp(desc->ltd_exp)->imp_connect_tried);

Sure, I suppose.  Using "desc" is a clean up.  Otherwise the original
code was not "silly".  It was fine.

I'm curious why you think if statements are less readable than other
statements.  That seems like nonsense.

regards,
dan carpenter



  reply	other threads:[~2014-07-20 11:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-19 19:34 staging: lustre/lustre/lov: Cleanup style issues in lov_request.c Riccardo Lucchese
2014-07-19 19:34 ` [PATCH 1/3] staging: lustre/lustre/lov: Remove unneeded 'if' statement in lov_request.c/lov_check_set() Riccardo Lucchese
2014-07-19 19:59   ` Joe Perches
2014-07-20 11:03     ` Riccardo Lucchese
2014-07-20  4:52   ` Dan Carpenter
2014-07-20 11:08     ` Riccardo Lucchese
2014-07-20 11:37       ` Dan Carpenter [this message]
2014-07-20 12:27         ` Riccardo Lucchese
2014-07-20 13:22         ` staging: lustre: lov: Cleanup style issues in lov_request.c Riccardo Lucchese
2014-07-20 13:22           ` [PATCH v2 1/3] staging: lustre: lov: Cleanup lov_check_set() " Riccardo Lucchese
2014-07-20 15:30             ` Joe Perches
2014-07-20 16:01               ` Riccardo Lucchese
2014-07-21 10:15               ` staging: lustre: lov: Cleanup style issues " Riccardo Lucchese
2014-07-21 10:15                 ` [PATCH v3 1/3] staging: lustre: lov: Cleanup lov_check_set() " Riccardo Lucchese
2014-07-21 10:15                 ` [PATCH v3 2/3] staging: lustre: lov: Add a blank line after declarations " Riccardo Lucchese
2014-07-21 10:19                 ` [PATCH v3 3/3] staging: lustre: lov: Add a space before open braces '{' " Riccardo Lucchese
2014-07-20 13:22           ` [PATCH v2 2/3] staging: lustre: lov: Add a blank line after declarations " Riccardo Lucchese
2014-07-20 13:22           ` [PATCH v2 3/3] staging: lustre: lov: Add a space before open braces '{' " Riccardo Lucchese
2014-07-19 19:34 ` [PATCH 2/3] staging: lustre/lustre/lov: Add a blank line after declarations " Riccardo Lucchese
2014-07-19 19:41 ` [PATCH 3/3] staging: lustre/lustre/lov: Add a space before open braces '{' " Riccardo Lucchese

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=20140720113747.GG18338@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg.drokin@intel.com \
    --cc=riccardo.lucchese@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox