linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] nfsd: remove private bin2hex implementation
@ 2019-10-11 16:02 Andy Shevchenko
  2019-10-11 16:49 ` J. Bruce Fields
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2019-10-11 16:02 UTC (permalink / raw)
  To: J. Bruce Fields, Chuck Lever, linux-nfs; +Cc: Andy Shevchenko

Calling sprintf in a loop is not very efficient, and in any case,
we already have an implementation of bin-to-hex conversion in lib/
which we might as well use.

Note that original code used to nul-terminate the destination while
bin2hex doesn't. That's why replace kmalloc() with kzalloc().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 fs/nfsd/nfs4recover.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index cdc75ad4438b..29dff4c6e752 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -1850,19 +1850,14 @@ nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *env0, char *env1)
 static char *
 bin_to_hex_dup(const unsigned char *src, int srclen)
 {
-	int i;
-	char *buf, *hex;
+	char *buf;
 
 	/* +1 for terminating NULL */
-	buf = kmalloc((srclen * 2) + 1, GFP_KERNEL);
+	buf = kzalloc((srclen * 2) + 1, GFP_KERNEL);
 	if (!buf)
 		return buf;
 
-	hex = buf;
-	for (i = 0; i < srclen; i++) {
-		sprintf(hex, "%2.2x", *src++);
-		hex += 2;
-	}
+	bin2hex(buf, src, srclen);
 	return buf;
 }
 
-- 
2.23.0


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

* Re: [PATCH v1] nfsd: remove private bin2hex implementation
  2019-10-11 16:02 [PATCH v1] nfsd: remove private bin2hex implementation Andy Shevchenko
@ 2019-10-11 16:49 ` J. Bruce Fields
  0 siblings, 0 replies; 2+ messages in thread
From: J. Bruce Fields @ 2019-10-11 16:49 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Chuck Lever, linux-nfs

Thanks, applying.--b.

On Fri, Oct 11, 2019 at 07:02:58PM +0300, Andy Shevchenko wrote:
> Calling sprintf in a loop is not very efficient, and in any case,
> we already have an implementation of bin-to-hex conversion in lib/
> which we might as well use.
> 
> Note that original code used to nul-terminate the destination while
> bin2hex doesn't. That's why replace kmalloc() with kzalloc().
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  fs/nfsd/nfs4recover.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
> index cdc75ad4438b..29dff4c6e752 100644
> --- a/fs/nfsd/nfs4recover.c
> +++ b/fs/nfsd/nfs4recover.c
> @@ -1850,19 +1850,14 @@ nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *env0, char *env1)
>  static char *
>  bin_to_hex_dup(const unsigned char *src, int srclen)
>  {
> -	int i;
> -	char *buf, *hex;
> +	char *buf;
>  
>  	/* +1 for terminating NULL */
> -	buf = kmalloc((srclen * 2) + 1, GFP_KERNEL);
> +	buf = kzalloc((srclen * 2) + 1, GFP_KERNEL);
>  	if (!buf)
>  		return buf;
>  
> -	hex = buf;
> -	for (i = 0; i < srclen; i++) {
> -		sprintf(hex, "%2.2x", *src++);
> -		hex += 2;
> -	}
> +	bin2hex(buf, src, srclen);
>  	return buf;
>  }
>  
> -- 
> 2.23.0

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

end of thread, other threads:[~2019-10-11 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-11 16:02 [PATCH v1] nfsd: remove private bin2hex implementation Andy Shevchenko
2019-10-11 16:49 ` J. Bruce Fields

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