* [resend][PATCH] fs: use kernel's hex_to_bin() method
@ 2010-12-10 10:55 Andy Shevchenko
2011-01-04 23:21 ` Andrew Morton
2011-01-05 9:54 ` David Howells
0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2010-12-10 10:55 UTC (permalink / raw)
To: linux-kernel
Cc: Andrew Morton, Andy Shevchenko, Alexander Viro, linux-fsdevel
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;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [resend][PATCH] fs: use kernel's hex_to_bin() method
2010-12-10 10:55 [resend][PATCH] fs: use kernel's hex_to_bin() method Andy Shevchenko
@ 2011-01-04 23:21 ` Andrew Morton
2011-01-04 23:58 ` Andy Shevchenko
2011-01-05 9:54 ` David Howells
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2011-01-04 23:21 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Alexander Viro, linux-fsdevel, Mimi Zohar,
Serge E. Hallyn, David Howells, James Morris
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;
_
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [resend][PATCH] fs: use kernel's hex_to_bin() method
2011-01-04 23:21 ` Andrew Morton
@ 2011-01-04 23:58 ` Andy Shevchenko
2011-01-05 0:14 ` Andrew Morton
2011-01-05 9:51 ` David Howells
0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2011-01-04 23:58 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Alexander Viro, linux-fsdevel, Mimi Zohar,
Serge E. Hallyn, David Howells, James Morris
On Wed, Jan 5, 2011 at 1:21 AM, Andrew Morton <akpm@linux-foundation.org> wrote:
> 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);
We need to update both p and s.
In case of '\xAA\xBB' you have result -> '0xBB'.
Am I wrong?
> continue;
> }
> *p++ = c;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [resend][PATCH] fs: use kernel's hex_to_bin() method
2011-01-04 23:58 ` Andy Shevchenko
@ 2011-01-05 0:14 ` Andrew Morton
2011-01-05 9:51 ` David Howells
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2011-01-05 0:14 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Alexander Viro, linux-fsdevel, Mimi Zohar,
Serge E. Hallyn, David Howells, James Morris
On Wed, 5 Jan 2011 01:58:56 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Wed, Jan 5, 2011 at 1:21 AM, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> > 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);
> We need to update both p and s.
>
> In case of '\xAA\xBB' you have result -> '0xBB'.
> Am I wrong?
>
> > continue;
> > }
> > *p++ = c;
I'm more into shopping and nagging at people than this programming
thingy. Sigh.
--- a/fs/binfmt_misc.c~fs-binfmt_miscc-use-kernels-hex_to_bin-method-fix-fix
+++ a/fs/binfmt_misc.c
@@ -243,11 +243,10 @@ static int unquote(char *from)
char c = 0, *s = from, *p = from;
while ((c = *s++) != '\0') {
- if (c == '\\' && *s == 'x') {
- s = (char *)hex2bin(p, s + 1, 1);
- continue;
- }
- *p++ = c;
+ if (c == '\\' && *s == 'x')
+ s = (char *)hex2bin(p++, s + 1, 1);
+ else
+ *p++ = c;
}
return p - from;
}
_
How does one test this thing?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [resend][PATCH] fs: use kernel's hex_to_bin() method
2011-01-04 23:58 ` Andy Shevchenko
2011-01-05 0:14 ` Andrew Morton
@ 2011-01-05 9:51 ` David Howells
1 sibling, 0 replies; 6+ messages in thread
From: David Howells @ 2011-01-05 9:51 UTC (permalink / raw)
To: Andrew Morton
Cc: dhowells, Andy Shevchenko, linux-kernel, Alexander Viro,
linux-fsdevel, Mimi Zohar, Serge E. Hallyn, James Morris
Andrew Morton <akpm@linux-foundation.org> wrote:
> How does one test this thing?
>From userspace.
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [resend][PATCH] fs: use kernel's hex_to_bin() method
2010-12-10 10:55 [resend][PATCH] fs: use kernel's hex_to_bin() method Andy Shevchenko
2011-01-04 23:21 ` Andrew Morton
@ 2011-01-05 9:54 ` David Howells
1 sibling, 0 replies; 6+ messages in thread
From: David Howells @ 2011-01-05 9:54 UTC (permalink / raw)
To: Andrew Morton
Cc: dhowells, Andy Shevchenko, linux-kernel, Alexander Viro,
linux-fsdevel, Mimi Zohar, Serge E. Hallyn, James Morris
Andrew Morton <akpm@linux-foundation.org> wrote:
> 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.
Maybe. You could always do as strchr():
char *strchr(const char *s, int c);
Then you don't need to cast the result. The problem[*] is that you can't tell
the compiler that the return value should carry the same constness as one of
the arguments because you don't have something like C++ templates.
[*] If indeed not having C++ or templates should be seen as a problem...
David
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-01-05 9:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-10 10:55 [resend][PATCH] fs: use kernel's hex_to_bin() method Andy Shevchenko
2011-01-04 23:21 ` Andrew Morton
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
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).