public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] sunrpc/cache.h: fix coding style
@ 2012-07-04 23:00 Eldad Zack
  2012-07-04 23:00 ` [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul Eldad Zack
  0 siblings, 1 reply; 8+ messages in thread
From: Eldad Zack @ 2012-07-04 23:00 UTC (permalink / raw)
  To: Trond Myklebust, J. Bruce Fields; +Cc: linux-nfs, linux-kernel, Eldad Zack

Neaten code style in get_int()

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
 include/linux/sunrpc/cache.h |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index f5fd616..0757887 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -220,10 +220,16 @@ static inline int get_int(char **bpp, int *anint)
 	char *ep;
 	int rv;
 	int len = qword_get(bpp, buf, 50);
-	if (len < 0) return -EINVAL;
-	if (len ==0) return -ENOENT;
+
+	if (len < 0)
+		return -EINVAL;
+	if (len == 0)
+		return -ENOENT;
+
 	rv = simple_strtol(buf, &ep, 0);
-	if (*ep) return -EINVAL;
+	if (*ep)
+		return -EINVAL;
+
 	*anint = rv;
 	return 0;
 }
-- 
1.7.10


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

* [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-04 23:00 [PATCH 1/2] sunrpc/cache.h: fix coding style Eldad Zack
@ 2012-07-04 23:00 ` Eldad Zack
  2012-07-04 23:23   ` Joe Perches
  2012-07-04 23:59   ` J. Bruce Fields
  0 siblings, 2 replies; 8+ messages in thread
From: Eldad Zack @ 2012-07-04 23:00 UTC (permalink / raw)
  To: Trond Myklebust, J. Bruce Fields; +Cc: linux-nfs, linux-kernel, Eldad Zack

This patch replaces the usage of simple_strtoul with kstrtoint in
get_int().

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
 include/linux/sunrpc/cache.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 0757887..9a60bcc 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -217,7 +217,7 @@ extern int qword_get(char **bpp, char *dest, int bufsize);
 static inline int get_int(char **bpp, int *anint)
 {
 	char buf[50];
-	char *ep;
+	ssize_t ret;
 	int rv;
 	int len = qword_get(bpp, buf, 50);
 
@@ -226,8 +226,8 @@ static inline int get_int(char **bpp, int *anint)
 	if (len == 0)
 		return -ENOENT;
 
-	rv = simple_strtol(buf, &ep, 0);
-	if (*ep)
+	ret = kstrtoint(buf, 0, &rv);
+	if (ret)
 		return -EINVAL;
 
 	*anint = rv;
-- 
1.7.10


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

* Re: [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-04 23:00 ` [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul Eldad Zack
@ 2012-07-04 23:23   ` Joe Perches
  2012-07-05 18:59     ` Eldad Zack
  2012-07-04 23:59   ` J. Bruce Fields
  1 sibling, 1 reply; 8+ messages in thread
From: Joe Perches @ 2012-07-04 23:23 UTC (permalink / raw)
  To: Eldad Zack; +Cc: Trond Myklebust, J. Bruce Fields, linux-nfs, linux-kernel

On Thu, 2012-07-05 at 01:00 +0200, Eldad Zack wrote:
> This patch replaces the usage of simple_strtoul with kstrtoint in
> get_int().

Just some trivia:

> diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
[]
> @@ -217,7 +217,7 @@ extern int qword_get(char **bpp, char *dest, int bufsize);
>  static inline int get_int(char **bpp, int *anint)
>  {
>  	char buf[50];
> -	char *ep;
> +	ssize_t ret;
>  	int rv;
>  	int len = qword_get(bpp, buf, 50);

This would be nicer as
	int len = qword_get(bpp, buf, sizeof(buf));

> @@ -226,8 +226,8 @@ static inline int get_int(char **bpp, int *anint)
>  	if (len == 0)
>  		return -ENOENT;
>  
> -	rv = simple_strtol(buf, &ep, 0);
> -	if (*ep)
> +	ret = kstrtoint(buf, 0, &rv);
> +	if (ret)
>  		return -EINVAL;
>  
>  	*anint = rv;

ret and rv aren't useful anymore.

Perhaps:

	if (kstrtoint(buf, 0, anint))
		return -EINVAL;

	return 0;



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

* Re: [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-04 23:00 ` [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul Eldad Zack
  2012-07-04 23:23   ` Joe Perches
@ 2012-07-04 23:59   ` J. Bruce Fields
  2012-07-05 19:04     ` Eldad Zack
  1 sibling, 1 reply; 8+ messages in thread
From: J. Bruce Fields @ 2012-07-04 23:59 UTC (permalink / raw)
  To: Eldad Zack; +Cc: Trond Myklebust, linux-nfs, linux-kernel

On Thu, Jul 05, 2012 at 01:00:26AM +0200, Eldad Zack wrote:
> This patch replaces the usage of simple_strtoul with kstrtoint in
> get_int().

Why?

--b.

> 
> Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
> ---
>  include/linux/sunrpc/cache.h |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
> index 0757887..9a60bcc 100644
> --- a/include/linux/sunrpc/cache.h
> +++ b/include/linux/sunrpc/cache.h
> @@ -217,7 +217,7 @@ extern int qword_get(char **bpp, char *dest, int bufsize);
>  static inline int get_int(char **bpp, int *anint)
>  {
>  	char buf[50];
> -	char *ep;
> +	ssize_t ret;
>  	int rv;
>  	int len = qword_get(bpp, buf, 50);
>  
> @@ -226,8 +226,8 @@ static inline int get_int(char **bpp, int *anint)
>  	if (len == 0)
>  		return -ENOENT;
>  
> -	rv = simple_strtol(buf, &ep, 0);
> -	if (*ep)
> +	ret = kstrtoint(buf, 0, &rv);
> +	if (ret)
>  		return -EINVAL;
>  
>  	*anint = rv;
> -- 
> 1.7.10
> 

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

* Re: [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-04 23:23   ` Joe Perches
@ 2012-07-05 18:59     ` Eldad Zack
  0 siblings, 0 replies; 8+ messages in thread
From: Eldad Zack @ 2012-07-05 18:59 UTC (permalink / raw)
  To: Joe Perches; +Cc: Trond Myklebust, J. Bruce Fields, linux-nfs, linux-kernel


On Wed, 4 Jul 2012, Joe Perches wrote:
> On Thu, 2012-07-05 at 01:00 +0200, Eldad Zack wrote:
> > This patch replaces the usage of simple_strtoul with kstrtoint in
> > get_int().
> 
> >  	int len = qword_get(bpp, buf, 50);
> This would be nicer as
> 	int len = qword_get(bpp, buf, sizeof(buf));

I agree, thanks!

> > @@ -226,8 +226,8 @@ static inline int get_int(char **bpp, int *anint)
> > +	ret = kstrtoint(buf, 0, &rv);
> > +	if (ret)
> >  		return -EINVAL;
> >  
> >  	*anint = rv;
> ret and rv aren't useful anymore.
> 
> Perhaps:
> 
> 	if (kstrtoint(buf, 0, anint))
> 		return -EINVAL;
> 
> 	return 0;

Yes, that works better, since kstrtoint() will not write to anint 
unless it's successful, so the whole business with rv is 
indeed redundant.

Looks much neater now thanks to your comments - I will resend it 
a bit later. Should I add you as Signed-off-by?

Eldad

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

* Re: [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-04 23:59   ` J. Bruce Fields
@ 2012-07-05 19:04     ` Eldad Zack
  2012-07-05 19:13       ` J. Bruce Fields
  0 siblings, 1 reply; 8+ messages in thread
From: Eldad Zack @ 2012-07-05 19:04 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Trond Myklebust, linux-nfs, linux-kernel


On Wed, 4 Jul 2012, J. Bruce Fields wrote:
> On Thu, Jul 05, 2012 at 01:00:26AM +0200, Eldad Zack wrote:
> > This patch replaces the usage of simple_strtoul with kstrtoint in
> > get_int().
> 
> Why?

Since the simple_str* family don't account for overflow and AFAIK
deprecated. Also, in this specific case, the long from strtol is 
silently converted to an int by the caller.

Eldad



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

* Re: [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-05 19:04     ` Eldad Zack
@ 2012-07-05 19:13       ` J. Bruce Fields
  2012-07-05 19:57         ` Eldad Zack
  0 siblings, 1 reply; 8+ messages in thread
From: J. Bruce Fields @ 2012-07-05 19:13 UTC (permalink / raw)
  To: Eldad Zack; +Cc: Trond Myklebust, linux-nfs, linux-kernel

On Thu, Jul 05, 2012 at 09:04:03PM +0200, Eldad Zack wrote:
> 
> On Wed, 4 Jul 2012, J. Bruce Fields wrote:
> > On Thu, Jul 05, 2012 at 01:00:26AM +0200, Eldad Zack wrote:
> > > This patch replaces the usage of simple_strtoul with kstrtoint in
> > > get_int().
> > 
> > Why?
> 
> Since the simple_str* family don't account for overflow and AFAIK
> deprecated. Also, in this specific case, the long from strtol is 
> silently converted to an int by the caller.

OK, thanks.  Please use that as the changelog when you resend.  ("This
patch replaces..." tells me nothing I couldn't figure out from looking
at the patch.)

--b.

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

* Re: [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul
  2012-07-05 19:13       ` J. Bruce Fields
@ 2012-07-05 19:57         ` Eldad Zack
  0 siblings, 0 replies; 8+ messages in thread
From: Eldad Zack @ 2012-07-05 19:57 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Trond Myklebust, linux-nfs, linux-kernel



On Thu, 5 Jul 2012, J. Bruce Fields wrote:

> On Thu, Jul 05, 2012 at 09:04:03PM +0200, Eldad Zack wrote:
> > 
> > On Wed, 4 Jul 2012, J. Bruce Fields wrote:
> > > On Thu, Jul 05, 2012 at 01:00:26AM +0200, Eldad Zack wrote:
> > > > This patch replaces the usage of simple_strtoul with kstrtoint in
> > > > get_int().
> > > 
> > > Why?
> > 
> > Since the simple_str* family don't account for overflow and AFAIK
> > deprecated. Also, in this specific case, the long from strtol is 
> > silently converted to an int by the caller.
> 
> OK, thanks.  Please use that as the changelog when you resend.  ("This
> patch replaces..." tells me nothing I couldn't figure out from looking
> at the patch.)

Will do, sorry about that.

Eldad

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

end of thread, other threads:[~2012-07-05 19:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-04 23:00 [PATCH 1/2] sunrpc/cache.h: fix coding style Eldad Zack
2012-07-04 23:00 ` [PATCH 2/2] sunrpc/cache.h: replace simple_strtoul Eldad Zack
2012-07-04 23:23   ` Joe Perches
2012-07-05 18:59     ` Eldad Zack
2012-07-04 23:59   ` J. Bruce Fields
2012-07-05 19:04     ` Eldad Zack
2012-07-05 19:13       ` J. Bruce Fields
2012-07-05 19:57         ` Eldad Zack

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox