Commit 3fc95772 authored by Harvey Harrison's avatar Harvey Harrison Committed by Linus Torvalds

lib: create common ascii hex array

Add a common hex array in hexdump.c so everyone can use it.

Add a common hi/lo helper to avoid the shifting masking that is
done to get the upper and lower nibbles of a byte value.

Pull the pack_hex_byte helper from kgdb as it is opencoded many
places in the tree that will be consolidated.
Signed-off-by: default avatarHarvey Harrison <harvey.harrison@gmail.com>
Acked-by: default avatarPaul Mundt <lethal@linux-sh.org>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 122a881c
...@@ -330,14 +330,6 @@ static char *ebin_to_mem(const char *buf, char *mem, int count) ...@@ -330,14 +330,6 @@ static char *ebin_to_mem(const char *buf, char *mem, int count)
return mem; return mem;
} }
/* Pack a hex byte */
static char *pack_hex_byte(char *pkt, int byte)
{
*pkt++ = hexchars[(byte >> 4) & 0xf];
*pkt++ = hexchars[(byte & 0xf)];
return pkt;
}
/* Scan for the start char '$', read the packet and check the checksum */ /* Scan for the start char '$', read the packet and check the checksum */
static void get_packet(char *buffer, int buflen) static void get_packet(char *buffer, int buflen)
{ {
......
...@@ -45,10 +45,10 @@ void pnp_eisa_id_to_string(u32 id, char *str) ...@@ -45,10 +45,10 @@ void pnp_eisa_id_to_string(u32 id, char *str)
str[0] = 'A' + ((id >> 26) & 0x3f) - 1; str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
str[1] = 'A' + ((id >> 21) & 0x1f) - 1; str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
str[2] = 'A' + ((id >> 16) & 0x1f) - 1; str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
str[3] = hex_asc((id >> 12) & 0xf); str[3] = hex_asc_hi(id >> 8);
str[4] = hex_asc((id >> 8) & 0xf); str[4] = hex_asc_lo(id >> 8);
str[5] = hex_asc((id >> 4) & 0xf); str[5] = hex_asc_hi(id);
str[6] = hex_asc((id >> 0) & 0xf); str[6] = hex_asc_lo(id);
str[7] = '\0'; str[7] = '\0';
} }
......
...@@ -276,7 +276,17 @@ extern void print_hex_dump(const char *level, const char *prefix_str, ...@@ -276,7 +276,17 @@ extern void print_hex_dump(const char *level, const char *prefix_str,
const void *buf, size_t len, bool ascii); const void *buf, size_t len, bool ascii);
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
const void *buf, size_t len); const void *buf, size_t len);
#define hex_asc(x) "0123456789abcdef"[x]
extern const char hex_asc[];
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
static inline char *pack_hex_byte(char *buf, u8 byte)
{
*buf++ = hex_asc_hi(byte);
*buf++ = hex_asc_lo(byte);
return buf;
}
#define pr_emerg(fmt, arg...) \ #define pr_emerg(fmt, arg...) \
printk(KERN_EMERG fmt, ##arg) printk(KERN_EMERG fmt, ##arg)
......
...@@ -346,14 +346,6 @@ static void put_packet(char *buffer) ...@@ -346,14 +346,6 @@ static void put_packet(char *buffer)
} }
} }
static char *pack_hex_byte(char *pkt, u8 byte)
{
*pkt++ = hexchars[byte >> 4];
*pkt++ = hexchars[byte & 0xf];
return pkt;
}
/* /*
* Convert the memory pointed to by mem into hex, placing result in buf. * Convert the memory pointed to by mem into hex, placing result in buf.
* Return a pointer to the last char put in buf (null). May return an error. * Return a pointer to the last char put in buf (null). May return an error.
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
const char hex_asc[] = "0123456789abcdef";
EXPORT_SYMBOL(hex_asc);
/** /**
* hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
* @buf: data blob to dump * @buf: data blob to dump
...@@ -93,8 +96,8 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, ...@@ -93,8 +96,8 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen; for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen;
j++) { j++) {
ch = ptr[j]; ch = ptr[j];
linebuf[lx++] = hex_asc(ch >> 4); linebuf[lx++] = hex_asc_hi(ch);
linebuf[lx++] = hex_asc(ch & 0x0f); linebuf[lx++] = hex_asc_lo(ch);
linebuf[lx++] = ' '; linebuf[lx++] = ' ';
} }
ascii_column = 3 * rowsize + 2; ascii_column = 3 * rowsize + 2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment