aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hexdump.c
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2010-05-24 17:33:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-25 11:07:05 -0400
commitdb0fd97c270f1e80321f7ae55234643ca0978c54 (patch)
tree1f825911c8c036e24b457873c74f8e9d16830775 /lib/hexdump.c
parent2b2f68b5383ea107295d7f1483256866e2daa1e3 (diff)
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: Joe Perches <joe@perches.com> Cc: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/hexdump.c')
-rw-r--r--lib/hexdump.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 39af2560f765..1bd6a9779774 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -34,7 +34,7 @@ EXPORT_SYMBOL(hex_asc);
34 * 34 *
35 * E.g.: 35 * E.g.:
36 * hex_dump_to_buffer(frame->data, frame->len, 16, 1, 36 * hex_dump_to_buffer(frame->data, frame->len, 16, 1,
37 * linebuf, sizeof(linebuf), 1); 37 * linebuf, sizeof(linebuf), true);
38 * 38 *
39 * example output buffer: 39 * example output buffer:
40 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO 40 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
@@ -65,8 +65,8 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
65 65
66 for (j = 0; j < ngroups; j++) 66 for (j = 0; j < ngroups; j++)
67 lx += scnprintf(linebuf + lx, linebuflen - lx, 67 lx += scnprintf(linebuf + lx, linebuflen - lx,
68 "%s%16.16llx", j ? " " : "", 68 "%s%16.16llx", j ? " " : "",
69 (unsigned long long)*(ptr8 + j)); 69 (unsigned long long)*(ptr8 + j));
70 ascii_column = 17 * ngroups + 2; 70 ascii_column = 17 * ngroups + 2;
71 break; 71 break;
72 } 72 }
@@ -77,7 +77,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
77 77
78 for (j = 0; j < ngroups; j++) 78 for (j = 0; j < ngroups; j++)
79 lx += scnprintf(linebuf + lx, linebuflen - lx, 79 lx += scnprintf(linebuf + lx, linebuflen - lx,
80 "%s%8.8x", j ? " " : "", *(ptr4 + j)); 80 "%s%8.8x", j ? " " : "", *(ptr4 + j));
81 ascii_column = 9 * ngroups + 2; 81 ascii_column = 9 * ngroups + 2;
82 break; 82 break;
83 } 83 }
@@ -88,7 +88,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
88 88
89 for (j = 0; j < ngroups; j++) 89 for (j = 0; j < ngroups; j++)
90 lx += scnprintf(linebuf + lx, linebuflen - lx, 90 lx += scnprintf(linebuf + lx, linebuflen - lx,
91 "%s%4.4x", j ? " " : "", *(ptr2 + j)); 91 "%s%4.4x", j ? " " : "", *(ptr2 + j));
92 ascii_column = 5 * ngroups + 2; 92 ascii_column = 5 * ngroups + 2;
93 break; 93 break;
94 } 94 }
@@ -111,9 +111,10 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
111 111
112 while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) 112 while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
113 linebuf[lx++] = ' '; 113 linebuf[lx++] = ' ';
114 for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) 114 for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) {
115 linebuf[lx++] = (isascii(ptr[j]) && isprint(ptr[j])) ? ptr[j] 115 ch = ptr[j];
116 : '.'; 116 linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
117 }
117nil: 118nil:
118 linebuf[lx++] = '\0'; 119 linebuf[lx++] = '\0';
119} 120}
@@ -143,7 +144,7 @@ EXPORT_SYMBOL(hex_dump_to_buffer);
143 * 144 *
144 * E.g.: 145 * E.g.:
145 * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, 146 * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS,
146 * 16, 1, frame->data, frame->len, 1); 147 * 16, 1, frame->data, frame->len, true);
147 * 148 *
148 * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: 149 * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
149 * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO 150 * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
@@ -151,12 +152,12 @@ EXPORT_SYMBOL(hex_dump_to_buffer);
151 * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. 152 * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~.
152 */ 153 */
153void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, 154void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
154 int rowsize, int groupsize, 155 int rowsize, int groupsize,
155 const void *buf, size_t len, bool ascii) 156 const void *buf, size_t len, bool ascii)
156{ 157{
157 const u8 *ptr = buf; 158 const u8 *ptr = buf;
158 int i, linelen, remaining = len; 159 int i, linelen, remaining = len;
159 unsigned char linebuf[200]; 160 unsigned char linebuf[32 * 3 + 2 + 32 + 1];
160 161
161 if (rowsize != 16 && rowsize != 32) 162 if (rowsize != 16 && rowsize != 32)
162 rowsize = 16; 163 rowsize = 16;
@@ -164,13 +165,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
164 for (i = 0; i < len; i += rowsize) { 165 for (i = 0; i < len; i += rowsize) {
165 linelen = min(remaining, rowsize); 166 linelen = min(remaining, rowsize);
166 remaining -= rowsize; 167 remaining -= rowsize;
168
167 hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, 169 hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
168 linebuf, sizeof(linebuf), ascii); 170 linebuf, sizeof(linebuf), ascii);
169 171
170 switch (prefix_type) { 172 switch (prefix_type) {
171 case DUMP_PREFIX_ADDRESS: 173 case DUMP_PREFIX_ADDRESS:
172 printk("%s%s%*p: %s\n", level, prefix_str, 174 printk("%s%s%p: %s\n",
173 (int)(2 * sizeof(void *)), ptr + i, linebuf); 175 level, prefix_str, ptr + i, linebuf);
174 break; 176 break;
175 case DUMP_PREFIX_OFFSET: 177 case DUMP_PREFIX_OFFSET:
176 printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); 178 printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
@@ -196,9 +198,9 @@ EXPORT_SYMBOL(print_hex_dump);
196 * rowsize of 16, groupsize of 1, and ASCII output included. 198 * rowsize of 16, groupsize of 1, and ASCII output included.
197 */ 199 */
198void print_hex_dump_bytes(const char *prefix_str, int prefix_type, 200void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
199 const void *buf, size_t len) 201 const void *buf, size_t len)
200{ 202{
201 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, 203 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
202 buf, len, 1); 204 buf, len, true);
203} 205}
204EXPORT_SYMBOL(print_hex_dump_bytes); 206EXPORT_SYMBOL(print_hex_dump_bytes);