lkml.org 
[lkml]   [2007]   [Dec]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Reduce stack used by lib/hexdump.c
On Thu, 29 Nov 2007 15:28:42 -0800
Joe Perches <joe@perches.com> wrote:

> On Thu, 2007-11-29 at 22:07 +0100, Jan Engelhardt wrote:
> > I'd add GFP_ATOMIC here. Who knows whether tomorrow, the oops dumper
> > or warn_on will use print_hex_dump.
>
> Signed-off-by: Joe Perches <joe@perches.com>
>
> diff --git a/lib/hexdump.c b/lib/hexdump.c
> index 70e23fb..be94934 100644
> --- a/lib/hexdump.c
> +++ b/lib/hexdump.c
> @@ -140,13 +140,20 @@ EXPORT_SYMBOL(hex_dump_to_buffer);
> * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
> * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~.
> */
> +
> +#define HEX_LINE_SIZE 200
> +
> void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
> int rowsize, int groupsize,
> const void *buf, size_t len, bool ascii)
> {
> const u8 *ptr = buf;
> int i, linelen, remaining = len;
> - unsigned char linebuf[200];
> + unsigned char *linebuf;
> +
> + linebuf = kmalloc(HEX_LINE_SIZE, GFP_ATOMIC);
> + if (!linebuf) {
> + WARN_ON(1);
> + return;
> + }

No, I think print_hex_dump() is too low-level to be doing allocations.
For example, one could easily choose to call print_hex_dump() at oops time,
and then what happens if we oops in kmalloc() (as we often do...)?

You could trim linebuf[] to 80 chars or so. Extra points for making it
very clear when someone tries to exceed that - strcpy(linebuf, "stop being
stupid").



\
 
 \ /
  Last update: 2007-12-06 01:05    [W:0.059 / U:0.228 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site