From dc88e46029486ed475c71fe1bb696d39511ac8fe Mon Sep 17 00:00:00 2001 From: Mimi Zohar Date: Tue, 23 Nov 2010 17:50:31 -0500 Subject: lib: hex2bin converts ascii hexadecimal string to binary Similar to the kgdb_hex2mem() code, hex2bin converts a string to binary using the hex_to_bin() library call. Changelog: - Replace parameter names with src/dst (based on David Howell's comment) - Add 'const' where needed (based on David Howell's comment) - Replace int with size_t (based on David Howell's comment) Signed-off-by: Mimi Zohar Acked-by: Serge E. Hallyn Acked-by: David Howells Signed-off-by: James Morris --- lib/hexdump.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/hexdump.c') diff --git a/lib/hexdump.c b/lib/hexdump.c index 5d7a4802c562..b66b2bd67952 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -33,6 +33,22 @@ int hex_to_bin(char ch) } EXPORT_SYMBOL(hex_to_bin); +/** + * hex2bin - convert an ascii hexadecimal string to its binary representation + * @dst: binary result + * @src: ascii hexadecimal string + * @count: result length + */ +void hex2bin(u8 *dst, const char *src, size_t count) +{ + while (count--) { + *dst = hex_to_bin(*src++) << 4; + *dst += hex_to_bin(*src++); + dst++; + } +} +EXPORT_SYMBOL(hex2bin); + /** * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory * @buf: data blob to dump -- cgit v1.2.2 From ac83ed687837a44c6e46fb16411fb0d299fffd80 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 12 Jan 2011 16:59:47 -0800 Subject: include/linux/printk.h lib/hexdump.c: neatening and add CONFIG_PRINTK guard - Move prototypes and align arguments. - Add CONFIG_PRINTK guard for print_hex functions Signed-off-by: Joe Perches Cc: Matt Mackall Cc: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/hexdump.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/hexdump.c') diff --git a/lib/hexdump.c b/lib/hexdump.c index b66b2bd67952..f5fe6ba7a3ab 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -154,6 +154,7 @@ nil: } EXPORT_SYMBOL(hex_dump_to_buffer); +#ifdef CONFIG_PRINTK /** * print_hex_dump - print a text hex dump to syslog for a binary blob of data * @level: kernel log level (e.g. KERN_DEBUG) @@ -238,3 +239,4 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type, buf, len, true); } EXPORT_SYMBOL(print_hex_dump_bytes); +#endif -- cgit v1.2.2