Skip to content

Commit

Permalink
ftrace: simplify hexprint
Browse files Browse the repository at this point in the history
simplify hex to ascii conversion.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Thomas Gleixner committed May 23, 2008
1 parent bb065af commit 93dcc6e
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,42 +248,29 @@ trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
}

#define HEX_CHARS 17
static const char hex2asc[] = "0123456789abcdef";

static int
trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
{
unsigned char hex[HEX_CHARS];
unsigned char *data;
unsigned char *data = mem;
unsigned char byte;
int i, j;

BUG_ON(len >= HEX_CHARS);

data = mem;

#ifdef __BIG_ENDIAN
for (i = 0, j = 0; i < len; i++) {
#else
for (i = len-1, j = 0; i >= 0; i--) {
#endif
byte = data[i];

hex[j] = byte & 0x0f;
if (hex[j] >= 10)
hex[j] += 'a' - 10;
else
hex[j] += '0';
j++;

hex[j] = byte >> 4;
if (hex[j] >= 10)
hex[j] += 'a' - 10;
else
hex[j] += '0';
j++;
hex[j++] = hex2asc[byte & 0x0f];
hex[j++] = hex2asc[byte >> 4];
}
hex[j] = ' ';
j++;
hex[j++] = ' ';

return trace_seq_putmem(s, hex, j);
}
Expand Down

0 comments on commit 93dcc6e

Please sign in to comment.