From: Joe Perches <joe@perches.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] Remove #define hex_asc from kernel.h, update lib/hexdump.c
Date: Thu, 29 Nov 2007 10:08:44 -0800 [thread overview]
Message-ID: <1196359724.22120.22.camel@localhost> (raw)
It's only use is in lib/hexdump.c
Instead, use scnprintf in lib/hexdump.c
Use "%0nx" not "%n.nx" (Smaller kernel, one byte at a time, woohoo!)
Use true not 1 for print_hex_dump
A bit of indentation style in lib/hexdump.c
Size before/after
text data bss dec hex filename
1037 0 0 1037 40d lib/hexdump.o
text data bss dec hex filename
1019 0 0 1019 3fb lib/hexdump.o
Signed-off-by: Joe Perches <joe@perches.com>
---
include/linux/kernel.h | 1 -
lib/hexdump.c | 23 ++++++++++-------------
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 94bc996..77b187f 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -256,7 +256,6 @@ extern void print_hex_dump(const char *level, const char *prefix_str,
const void *buf, size_t len, bool ascii);
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
const void *buf, size_t len);
-#define hex_asc(x) "0123456789abcdef"[x]
#define pr_emerg(fmt, arg...) \
printk(KERN_EMERG fmt, ##arg)
diff --git a/lib/hexdump.c b/lib/hexdump.c
index bd5edae..70e23fb 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -41,7 +41,6 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
bool ascii)
{
const u8 *ptr = buf;
- u8 ch;
int j, lx = 0;
int ascii_column;
@@ -62,7 +61,9 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
for (j = 0; j < ngroups; j++)
lx += scnprintf(linebuf + lx, linebuflen - lx,
- "%16.16llx ", (unsigned long long)*(ptr8 + j));
+ "%016llx ",
+ (unsigned long long)*(ptr8 + j) &
+ 0xffffffffffffffffULL);
ascii_column = 17 * ngroups + 2;
break;
}
@@ -73,7 +74,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
for (j = 0; j < ngroups; j++)
lx += scnprintf(linebuf + lx, linebuflen - lx,
- "%8.8x ", *(ptr4 + j));
+ "%08x ", *(ptr4 + j) & 0xffffffffU);
ascii_column = 9 * ngroups + 2;
break;
}
@@ -84,19 +85,15 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
for (j = 0; j < ngroups; j++)
lx += scnprintf(linebuf + lx, linebuflen - lx,
- "%4.4x ", *(ptr2 + j));
+ "%04x ", *(ptr2 + j) & 0xffff);
ascii_column = 5 * ngroups + 2;
break;
}
default:
- for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen;
- j++) {
- ch = ptr[j];
- linebuf[lx++] = hex_asc(ch >> 4);
- linebuf[lx++] = hex_asc(ch & 0x0f);
- linebuf[lx++] = ' ';
- }
+ for (j = 0; (j < rowsize) && (j < len) < linebuflen; j++)
+ lx += scnprintf(linebuf + lx, linebuflen - lx,
+ "%02x ", ptr[j] & 0xff);
ascii_column = 3 * rowsize + 2;
break;
}
@@ -163,7 +160,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
switch (prefix_type) {
case DUMP_PREFIX_ADDRESS:
printk("%s%s%*p: %s\n", level, prefix_str,
- (int)(2 * sizeof(void *)), ptr + i, linebuf);
+ (int)(2 * sizeof(void *)), ptr + i, linebuf);
break;
case DUMP_PREFIX_OFFSET:
printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
@@ -192,6 +189,6 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
const void *buf, size_t len)
{
print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
- buf, len, 1);
+ buf, len, true);
}
EXPORT_SYMBOL(print_hex_dump_bytes);
next reply other threads:[~2007-11-29 18:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-29 18:08 Joe Perches [this message]
2007-11-29 18:24 ` [PATCH] Remove #define hex_asc from kernel.h, update lib/hexdump.c Randy Dunlap
2007-11-29 18:44 ` Joe Perches
2007-11-29 18:52 ` Randy Dunlap
2007-11-29 18:55 ` Joe Perches
2007-11-29 20:57 ` [PATCH] Reduce stack used by lib/hexdump.c Joe Perches
2007-11-29 21:02 ` Randy Dunlap
2007-11-29 21:07 ` Jan Engelhardt
2007-11-29 23:28 ` Joe Perches
2007-12-06 0:01 ` Andrew Morton
2007-12-06 2:10 ` Joe Perches
2007-12-06 2:18 ` Randy Dunlap
2007-12-06 2:42 ` Joe Perches
2007-12-06 5:58 ` Kyle Moffett
2007-12-06 7:10 ` Andrew Morton
2007-12-06 21:52 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1196359724.22120.22.camel@localhost \
--to=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).