diff options
Diffstat (limited to 'lib/hexdump.c')
| -rw-r--r-- | lib/hexdump.c | 31 | 
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/hexdump.c b/lib/hexdump.c index 5d7a4802c56..8499c810909 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -10,10 +10,12 @@  #include <linux/types.h>  #include <linux/ctype.h>  #include <linux/kernel.h> -#include <linux/module.h> +#include <linux/export.h>  const char hex_asc[] = "0123456789abcdef";  EXPORT_SYMBOL(hex_asc); +const char hex_asc_upper[] = "0123456789ABCDEF"; +EXPORT_SYMBOL(hex_asc_upper);  /**   * hex_to_bin - convert a hex digit to its real value @@ -34,6 +36,29 @@ 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 + * + * Return 0 on success, -1 in case of bad input. + */ +int hex2bin(u8 *dst, const char *src, size_t count) +{ +	while (count--) { +		int hi = hex_to_bin(*src++); +		int lo = hex_to_bin(*src++); + +		if ((hi < 0) || (lo < 0)) +			return -1; + +		*dst++ = (hi << 4) | lo; +	} +	return 0; +} +EXPORT_SYMBOL(hex2bin); + +/**   * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory   * @buf: data blob to dump   * @len: number of bytes in the @buf @@ -138,6 +163,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) @@ -203,6 +229,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,  }  EXPORT_SYMBOL(print_hex_dump); +#if !defined(CONFIG_DYNAMIC_DEBUG)  /**   * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params   * @prefix_str: string to prefix each line with; @@ -222,3 +249,5 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type,  		       buf, len, true);  }  EXPORT_SYMBOL(print_hex_dump_bytes); +#endif /* !defined(CONFIG_DYNAMIC_DEBUG) */ +#endif /* defined(CONFIG_PRINTK) */  | 
