* [PATCH 1/2, resend] sunrpc/cache.h: fix coding style
@ 2012-07-06 19:31 Eldad Zack
2012-07-06 19:31 ` [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul Eldad Zack
0 siblings, 1 reply; 4+ messages in thread
From: Eldad Zack @ 2012-07-06 19:31 UTC (permalink / raw)
To: J. Bruce Fields, Trond Myklebust
Cc: Joe Perches, linux-nfs, linux-kernel, Eldad Zack
Neaten code style in get_int().
Also use sizeof() instead of hard coded number as suggested by
Joe Perches <joe@perches.com>.
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
Resent to include improvements from Joe Perches.
include/linux/sunrpc/cache.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index f5fd616..6def1f6 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -219,11 +219,17 @@ static inline int get_int(char **bpp, int *anint)
char buf[50];
char *ep;
int rv;
- int len = qword_get(bpp, buf, 50);
- if (len < 0) return -EINVAL;
- if (len ==0) return -ENOENT;
+ int len = qword_get(bpp, buf, sizeof(buf));
+
+ 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 [flat|nested] 4+ messages in thread
* [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul
2012-07-06 19:31 [PATCH 1/2, resend] sunrpc/cache.h: fix coding style Eldad Zack
@ 2012-07-06 19:31 ` Eldad Zack
2012-07-10 16:31 ` J. Bruce Fields
0 siblings, 1 reply; 4+ messages in thread
From: Eldad Zack @ 2012-07-06 19:31 UTC (permalink / raw)
To: J. Bruce Fields, Trond Myklebust
Cc: Joe Perches, linux-nfs, linux-kernel, Eldad Zack
This patch replaces the usage of simple_strtoul with kstrtoint in
get_int(), since the simple_str* family doesn't account for overflow
and is deprecated.
Also, in this specific case, the long from strtol is silently converted
to an int by the caller.
As Joe Perches <joe@perches.com> suggested, this patch also removes
the redundant temporary variable rv, since kstrtoint() will not write to
anint unless it's successful.
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
Resent to include improvements from Joe Perches and proper changelog as
J. Bruce Fields kindly pointed out.
include/linux/sunrpc/cache.h | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 6def1f6..af42596 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -217,8 +217,6 @@ extern int qword_get(char **bpp, char *dest, int bufsize);
static inline int get_int(char **bpp, int *anint)
{
char buf[50];
- char *ep;
- int rv;
int len = qword_get(bpp, buf, sizeof(buf));
if (len < 0)
@@ -226,11 +224,9 @@ static inline int get_int(char **bpp, int *anint)
if (len == 0)
return -ENOENT;
- rv = simple_strtol(buf, &ep, 0);
- if (*ep)
+ if (kstrtoint(buf, 0, anint))
return -EINVAL;
- *anint = rv;
return 0;
}
--
1.7.10
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul
2012-07-06 19:31 ` [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul Eldad Zack
@ 2012-07-10 16:31 ` J. Bruce Fields
2012-07-12 20:54 ` Eldad Zack
0 siblings, 1 reply; 4+ messages in thread
From: J. Bruce Fields @ 2012-07-10 16:31 UTC (permalink / raw)
To: Eldad Zack; +Cc: Trond Myklebust, Joe Perches, linux-nfs, linux-kernel
Thanks, applying.
On Fri, Jul 06, 2012 at 09:31:57PM +0200, Eldad Zack wrote:
> This patch replaces the usage of simple_strtoul with kstrtoint in
> get_int(), since the simple_str* family doesn't account for overflow
> and is deprecated.
> Also, in this specific case, the long from strtol is silently converted
> to an int by the caller.
(By the way, one advantage which simple_str* does have is documentation.
Some kerneldoc comments might be helpful for kstrto* as well?)
--b.
>
> As Joe Perches <joe@perches.com> suggested, this patch also removes
> the redundant temporary variable rv, since kstrtoint() will not write to
> anint unless it's successful.
>
> Cc: Joe Perches <joe@perches.com>
> Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
> ---
> Resent to include improvements from Joe Perches and proper changelog as
> J. Bruce Fields kindly pointed out.
> include/linux/sunrpc/cache.h | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
> index 6def1f6..af42596 100644
> --- a/include/linux/sunrpc/cache.h
> +++ b/include/linux/sunrpc/cache.h
> @@ -217,8 +217,6 @@ extern int qword_get(char **bpp, char *dest, int bufsize);
> static inline int get_int(char **bpp, int *anint)
> {
> char buf[50];
> - char *ep;
> - int rv;
> int len = qword_get(bpp, buf, sizeof(buf));
>
> if (len < 0)
> @@ -226,11 +224,9 @@ static inline int get_int(char **bpp, int *anint)
> if (len == 0)
> return -ENOENT;
>
> - rv = simple_strtol(buf, &ep, 0);
> - if (*ep)
> + if (kstrtoint(buf, 0, anint))
> return -EINVAL;
>
> - *anint = rv;
> return 0;
> }
>
> --
> 1.7.10
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul
2012-07-10 16:31 ` J. Bruce Fields
@ 2012-07-12 20:54 ` Eldad Zack
0 siblings, 0 replies; 4+ messages in thread
From: Eldad Zack @ 2012-07-12 20:54 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: Trond Myklebust, Joe Perches, linux-nfs, linux-kernel
On Tue, 10 Jul 2012, J. Bruce Fields wrote:
>
> (By the way, one advantage which simple_str* does have is documentation.
Not for long :)
Eldad
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-07-12 20:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-06 19:31 [PATCH 1/2, resend] sunrpc/cache.h: fix coding style Eldad Zack
2012-07-06 19:31 ` [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul Eldad Zack
2012-07-10 16:31 ` J. Bruce Fields
2012-07-12 20:54 ` Eldad Zack
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome