sunrpc/cache.h: fix coding style
Subsystems (2)
PATCH RESEND 1/2 sunrpc/cache.h: fix coding style
Neaten code style in get_int().
Also use sizeof() instead of hard coded number as suggested by Joe Perches <[email protected]>.
---
Resent to include improvements from Joe Perches.
include/linux/sunrpc/cache.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
include/linux/sunrpc/cache.h +10 -4
@@ -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 ; }
Signature · 1 line
1.7.10
PATCH RESEND 2/2 sunrpc/cache.h: replace simple_strtoul
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 <[email protected]> suggested, this patch also removes the redundant temporary variable rv, since kstrtoint() will not write to anint unless it's successful.
---
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(-)
include/linux/sunrpc/cache.h +1 -5
@@ -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 ; }
Signature · 1 line
1.7.10
Re: [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul
Thanks, applying.
Quoted 5 lines · Eldad Zack
This patch replaces the usage of
simple_strtoulwith kstrtoint inget_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.
Quoted 42 lines
As Joe Perches <[email protected]> suggested, this patch also removes the redundant temporary variable rv, since
kstrtoint()will not write to anint unless it's successful.Cc Joe Perches <[email protected]>Signed-off-by Eldad Zack <[email protected]>---
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(-)include/linux/sunrpc/cache.h +1
-5@@ -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 ; }Signature · 1 line
1.7.10
Re: [PATCH 2/2,resend] sunrpc/cache.h: replace simple_strtoul
Quoted 2 lines · J. Bruce Fields
(By the way, one advantage which simple_str* does have is documentation.
Not for long :)
Eldad