linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] aoe: remove custom implementation of kbasename()
@ 2013-08-01 12:28 Andy Shevchenko
  2013-08-01 12:28 ` [PATCH 2/2] aoe: use min() to simplify the code Andy Shevchenko
  2013-08-02  1:04 ` [PATCH 1/2] aoe: remove custom implementation of kbasename() Ed Cashin
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2013-08-01 12:28 UTC (permalink / raw)
  To: Ed Cashin, linux-kernel; +Cc: Andy Shevchenko

In the kernel we have a nice helper that may be used here. This patch
substitutes the custom implementation by the native function call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/block/aoe/aoedev.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index 784c92e..db35ef6 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -12,6 +12,7 @@
 #include <linux/bitmap.h>
 #include <linux/kdev_t.h>
 #include <linux/moduleparam.h>
+#include <linux/string.h>
 #include "aoe.h"
 
 static void dummy_timer(ulong);
@@ -241,16 +242,12 @@ aoedev_downdev(struct aoedev *d)
 static int
 user_req(char *s, size_t slen, struct aoedev *d)
 {
-	char *p;
+	const char *p;
 	size_t lim;
 
 	if (!d->gd)
 		return 0;
-	p = strrchr(d->gd->disk_name, '/');
-	if (!p)
-		p = d->gd->disk_name;
-	else
-		p += 1;
+	p = kbasename(d->gd->disk_name);
 	lim = sizeof(d->gd->disk_name);
 	lim -= p - d->gd->disk_name;
 	if (slen < lim)
-- 
1.8.3.2


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

* [PATCH 2/2] aoe: use min() to simplify the code
  2013-08-01 12:28 [PATCH 1/2] aoe: remove custom implementation of kbasename() Andy Shevchenko
@ 2013-08-01 12:28 ` Andy Shevchenko
  2013-08-02  1:13   ` Ed Cashin
  2013-08-02  1:04 ` [PATCH 1/2] aoe: remove custom implementation of kbasename() Ed Cashin
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2013-08-01 12:28 UTC (permalink / raw)
  To: Ed Cashin, linux-kernel; +Cc: Andy Shevchenko

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


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

* Re: [PATCH 1/2] aoe: remove custom implementation of kbasename()
  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:04 ` Ed Cashin
  1 sibling, 0 replies; 5+ messages in thread
From: Ed Cashin @ 2013-08-02  1:04 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-kernel, Andrew Morton

Looks OK.  Thanks.

On Aug 1, 2013, at 8:28 AM, Andy Shevchenko wrote:

> In the kernel we have a nice helper that may be used here. This patch
> substitutes the custom implementation by the native function call.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/block/aoe/aoedev.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
> index 784c92e..db35ef6 100644
> --- a/drivers/block/aoe/aoedev.c
> +++ b/drivers/block/aoe/aoedev.c
> @@ -12,6 +12,7 @@
> #include <linux/bitmap.h>
> #include <linux/kdev_t.h>
> #include <linux/moduleparam.h>
> +#include <linux/string.h>
> #include "aoe.h"
> 
> static void dummy_timer(ulong);
> @@ -241,16 +242,12 @@ aoedev_downdev(struct aoedev *d)
> static int
> user_req(char *s, size_t slen, struct aoedev *d)
> {
> -	char *p;
> +	const char *p;
> 	size_t lim;
> 
> 	if (!d->gd)
> 		return 0;
> -	p = strrchr(d->gd->disk_name, '/');
> -	if (!p)
> -		p = d->gd->disk_name;
> -	else
> -		p += 1;
> +	p = kbasename(d->gd->disk_name);
> 	lim = sizeof(d->gd->disk_name);
> 	lim -= p - d->gd->disk_name;
> 	if (slen < lim)
> -- 
> 1.8.3.2
> 

-- 
  Ed Cashin
  ecashin@coraid.com



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

* Re: [PATCH 2/2] aoe: use min() to simplify the code
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Ed Cashin @ 2013-08-02  1:13 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-kernel, Andrew Morton

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?

On Aug 1, 2013, at 8:28 AM, Andy Shevchenko wrote:

> 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
> 

-- 
  Ed Cashin
  ecashin@coraid.com



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

* Re: [PATCH 2/2] aoe: use min() to simplify the code
  2013-08-02  1:13   ` Ed Cashin
@ 2013-08-02  9:15     ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2013-08-02  9:15 UTC (permalink / raw)
  To: Ed Cashin; +Cc: linux-kernel, Andrew Morton

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

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

end of thread, other threads:[~2013-08-02  9:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2013-08-02  1:04 ` [PATCH 1/2] aoe: remove custom implementation of kbasename() Ed Cashin

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).