linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, Mimi Zohar <zohar@us.ibm.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	David Howells <dhowells@redhat.com>,
	James Morris <jmorris@namei.org>
Subject: Re: [resend][PATCH] fs: use kernel's hex_to_bin() method
Date: Tue, 4 Jan 2011 15:21:00 -0800	[thread overview]
Message-ID: <20110104152100.29d0da02.akpm@linux-foundation.org> (raw)
In-Reply-To: <1291978505-29076-1-git-send-email-andy.shevchenko@gmail.com>

On Fri, 10 Dec 2010 12:55:05 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: linux-fsdevel@vger.kernel.org
> ---
>  fs/binfmt_misc.c |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
> index 1befe2e..a0fb271 100644
> --- a/fs/binfmt_misc.c
> +++ b/fs/binfmt_misc.c
> @@ -28,6 +28,7 @@
>  #include <linux/mount.h>
>  #include <linux/syscalls.h>
>  #include <linux/fs.h>
> +#include <linux/kernel.h>
>  
>  #include <asm/uaccess.h>
>  
> @@ -244,10 +245,8 @@ static int unquote(char *from)
>  	while ((c = *s++) != '\0') {
>  		if (c == '\\' && *s == 'x') {
>  			s++;
> -			c = toupper(*s++);
> -			*p = (c - (isdigit(c) ? '0' : 'A' - 10)) << 4;
> -			c = toupper(*s++);
> -			*p++ |= c - (isdigit(c) ? '0' : 'A' - 10);
> +			*p = hex_to_bin(*s++) << 4;
> +			*p++ |= hex_to_bin(*s++);
>  			continue;
>  		}
>  		*p++ = c;

Calling hex_to_bin() twice is a bit sad - we need a library function
which does hex-to-bin on a digit string.

And lo, one just got added in linux-next.  However it cruelly didn't
return anything useful, so...

From: Andrew Morton <akpm@linux-foundation.org>

As a convenience to callers.

Not a terribly convenient convenience, as most callers will need to cast
away the constness of the return value.  Oh well, those callers should
have been using a `const char *' anyway.

Cc: Mimi Zohar <zohar@us.ibm.com>
Cc: Serge E. Hallyn <serge@hallyn.com>
Cc: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/kernel.h |    2 +-
 lib/hexdump.c          |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff -puN lib/hexdump.c~lib-hexdumpc-make-hex2bin-return-the-updated-src-address lib/hexdump.c
--- a/lib/hexdump.c~lib-hexdumpc-make-hex2bin-return-the-updated-src-address
+++ a/lib/hexdump.c
@@ -39,13 +39,14 @@ EXPORT_SYMBOL(hex_to_bin);
  * @src: ascii hexadecimal string
  * @count: result length
  */
-void hex2bin(u8 *dst, const char *src, size_t count)
+const char *hex2bin(u8 *dst, const char *src, size_t count)
 {
 	while (count--) {
 		*dst = hex_to_bin(*src++) << 4;
 		*dst += hex_to_bin(*src++);
 		dst++;
 	}
+	return src;
 }
 EXPORT_SYMBOL(hex2bin);
 
diff -puN include/linux/kernel.h~lib-hexdumpc-make-hex2bin-return-the-updated-src-address include/linux/kernel.h
--- a/include/linux/kernel.h~lib-hexdumpc-make-hex2bin-return-the-updated-src-address
+++ a/include/linux/kernel.h
@@ -278,7 +278,7 @@ static inline char *pack_hex_byte(char *
 }
 
 extern int hex_to_bin(char ch);
-extern void hex2bin(u8 *dst, const char *src, size_t count);
+extern const char *hex2bin(u8 *dst, const char *src, size_t count);
 
 /*
  * General tracing related utility functions - trace_printk(),
_


After which we can change your patch thusly:

--- a/fs/binfmt_misc.c~fs-binfmt_miscc-use-kernels-hex_to_bin-method-fix
+++ a/fs/binfmt_misc.c
@@ -244,9 +244,7 @@ static int unquote(char *from)
 
 	while ((c = *s++) != '\0') {
 		if (c == '\\' && *s == 'x') {
-			s++;
-			*p = hex_to_bin(*s++) << 4;
-			*p++ |= hex_to_bin(*s++);
+			s = (char *)hex2bin(p, s + 1, 1);
 			continue;
 		}
 		*p++ = c;
_

  reply	other threads:[~2011-01-04 23:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-10 10:55 [resend][PATCH] fs: use kernel's hex_to_bin() method Andy Shevchenko
2011-01-04 23:21 ` Andrew Morton [this message]
2011-01-04 23:58   ` Andy Shevchenko
2011-01-05  0:14     ` Andrew Morton
2011-01-05  9:51     ` David Howells
2011-01-05  9:54 ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110104152100.29d0da02.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=jmorris@namei.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).