Commit db0fd97c authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

lib/hexdump.c: reduce stack variable size and cleanups

Reduce char linebuf[200] to the actual size required., which is 32 * 3 + 2
+ 32 + 1, ie: linebuf[131].

Change examples to use bool true not int 1.

Align multiline argument indentation to open parenthesis.

Use temporary for ptr[j] so trigraph fits on single line.

Convert printk ptr from %*p, (int)(2 * sizeof(void *)) to %p as %p uses
the same calculation for size.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2b2f68b5
...@@ -34,7 +34,7 @@ EXPORT_SYMBOL(hex_asc); ...@@ -34,7 +34,7 @@ EXPORT_SYMBOL(hex_asc);
* *
* E.g.: * E.g.:
* hex_dump_to_buffer(frame->data, frame->len, 16, 1, * hex_dump_to_buffer(frame->data, frame->len, 16, 1,
* linebuf, sizeof(linebuf), 1); * linebuf, sizeof(linebuf), true);
* *
* example output buffer: * example output buffer:
* 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
...@@ -111,9 +111,10 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, ...@@ -111,9 +111,10 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
linebuf[lx++] = ' '; linebuf[lx++] = ' ';
for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) {
linebuf[lx++] = (isascii(ptr[j]) && isprint(ptr[j])) ? ptr[j] ch = ptr[j];
: '.'; linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
}
nil: nil:
linebuf[lx++] = '\0'; linebuf[lx++] = '\0';
} }
...@@ -143,7 +144,7 @@ EXPORT_SYMBOL(hex_dump_to_buffer); ...@@ -143,7 +144,7 @@ EXPORT_SYMBOL(hex_dump_to_buffer);
* *
* E.g.: * E.g.:
* print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS,
* 16, 1, frame->data, frame->len, 1); * 16, 1, frame->data, frame->len, true);
* *
* Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
* 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
...@@ -156,7 +157,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, ...@@ -156,7 +157,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
{ {
const u8 *ptr = buf; const u8 *ptr = buf;
int i, linelen, remaining = len; int i, linelen, remaining = len;
unsigned char linebuf[200]; unsigned char linebuf[32 * 3 + 2 + 32 + 1];
if (rowsize != 16 && rowsize != 32) if (rowsize != 16 && rowsize != 32)
rowsize = 16; rowsize = 16;
...@@ -164,13 +165,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, ...@@ -164,13 +165,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
for (i = 0; i < len; i += rowsize) { for (i = 0; i < len; i += rowsize) {
linelen = min(remaining, rowsize); linelen = min(remaining, rowsize);
remaining -= rowsize; remaining -= rowsize;
hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
linebuf, sizeof(linebuf), ascii); linebuf, sizeof(linebuf), ascii);
switch (prefix_type) { switch (prefix_type) {
case DUMP_PREFIX_ADDRESS: case DUMP_PREFIX_ADDRESS:
printk("%s%s%*p: %s\n", level, prefix_str, printk("%s%s%p: %s\n",
(int)(2 * sizeof(void *)), ptr + i, linebuf); level, prefix_str, ptr + i, linebuf);
break; break;
case DUMP_PREFIX_OFFSET: case DUMP_PREFIX_OFFSET:
printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
...@@ -199,6 +201,6 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type, ...@@ -199,6 +201,6 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
const void *buf, size_t len) const void *buf, size_t len)
{ {
print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
buf, len, 1); buf, len, true);
} }
EXPORT_SYMBOL(print_hex_dump_bytes); EXPORT_SYMBOL(print_hex_dump_bytes);
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