public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Ed Cashin <ecashin@coraid.com>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 2/2] aoe: use min() to simplify the code
Date: Fri, 02 Aug 2013 12:15:11 +0300	[thread overview]
Message-ID: <1375434911.31118.74.camel@smile> (raw)
In-Reply-To: <5B6F37C8-CB08-4BA6-9AC9-D328711385F9@coraid.com>

On Thu, 2013-08-01 at 21:13 -0400, Ed Cashin wrote: 
> Thanks.
> 
> I agree that we could do that.  I'm not sure it increases readability to put this much stuff on one line, though.  What is the motivation?

Motivation is to explicitly show that that operation is to calculate a
minimum of two the slen parameter and the length of last part of the
disk_name.

It seems matter of taste, so, I'm okay with current piece of code.

> > min() incorporates condition in it. In our case we could do assignment and
> > make a choice at once.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> > drivers/block/aoe/aoedev.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
> > index db35ef6..92fadfa 100644
> > --- a/drivers/block/aoe/aoedev.c
> > +++ b/drivers/block/aoe/aoedev.c
> > @@ -13,6 +13,7 @@
> > #include <linux/kdev_t.h>
> > #include <linux/moduleparam.h>
> > #include <linux/string.h>
> > +#include <linux/kernel.h>
> > #include "aoe.h"
> > 
> > static void dummy_timer(ulong);
> > @@ -248,10 +249,7 @@ user_req(char *s, size_t slen, struct aoedev *d)
> > 	if (!d->gd)
> > 		return 0;
> > 	p = kbasename(d->gd->disk_name);
> > -	lim = sizeof(d->gd->disk_name);
> > -	lim -= p - d->gd->disk_name;
> > -	if (slen < lim)
> > -		lim = slen;
> > +	lim = min(sizeof(d->gd->disk_name) - (p - d->gd->disk_name), slen);
> > 
> > 	return !strncmp(s, p, lim);
> > }
> > -- 
> > 1.8.3.2
> > 
> 

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

  reply	other threads:[~2013-08-02  9:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01 12:28 [PATCH 1/2] aoe: remove custom implementation of kbasename() Andy Shevchenko
2013-08-01 12:28 ` [PATCH 2/2] aoe: use min() to simplify the code Andy Shevchenko
2013-08-02  1:13   ` Ed Cashin
2013-08-02  9:15     ` Andy Shevchenko [this message]
2013-08-02  1:04 ` [PATCH 1/2] aoe: remove custom implementation of kbasename() Ed Cashin

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=1375434911.31118.74.camel@smile \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=ecashin@coraid.com \
    --cc=linux-kernel@vger.kernel.org \
    /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