linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Randy Dunlap <randy.dunlap@oracle.com>
To: Joe Perches <joe@perches.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Reduce stack used by lib/hexdump.c
Date: Thu, 29 Nov 2007 13:02:35 -0800	[thread overview]
Message-ID: <474F28EB.20608@oracle.com> (raw)
In-Reply-To: <1196369873.22120.69.camel@localhost>

Joe Perches wrote:
> 200 bytes on stack might be a bit much.
> 
> Size goes up to
>    text    data     bss     dec     hex filename
>    1142       0       0    1142     476 lib/hexdump.o
> Without the WARN_ON
>    1053       0       0    1053     41d lib/hexdump.o
> Before this patch
>    1004       0       0    1004     3ec lib/hexdump.o
> 
> Win some/lose some...
> 
> Signed-off-by: Joe Perches <joe@perches.com>

Acked-by: Randy Dunlap <randy.dunlap@oracle.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_KERNEL);
> +	if (!linebuf) {
> +		WARN_ON(1);
> +		return;
> +	}
>  
>  	if (rowsize != 16 && rowsize != 32)
>  		rowsize = 16;
> @@ -155,7 +162,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
>  		linelen = min(remaining, rowsize);
>  		remaining -= rowsize;
>  		hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
> -				linebuf, sizeof(linebuf), ascii);
> +				linebuf, HEX_LINE_SIZE, ascii);
>  
>  		switch (prefix_type) {
>  		case DUMP_PREFIX_ADDRESS:
> @@ -170,6 +177,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
>  			break;
>  		}
>  	}
> +	kfree(linebuf);
>  }
>  EXPORT_SYMBOL(print_hex_dump);


-- 
~Randy

  reply	other threads:[~2007-11-29 21:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29 18:08 [PATCH] Remove #define hex_asc from kernel.h, update lib/hexdump.c Joe Perches
2007-11-29 18:24 ` 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 [this message]
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=474F28EB.20608@oracle.com \
    --to=randy.dunlap@oracle.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.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).