Skip to content

Commit

Permalink
sprint_symbol(): use less stack
Browse files Browse the repository at this point in the history
sprint_symbol(), itself used when dumping stacks, has been wasting 128
bytes of stack: lookup the symbol directly into the buffer supplied by the
caller, instead of using a locally declared namebuf.

I believe the name != buffer strcpy() is obsolete: the design here dates
from when module symbol lookup pointed into a supposedly const but sadly
volatile table; nowadays it copies, but an uncalled strcpy() looks better
here than the risk of a recursive BUG_ON().

Signed-off-by: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Hugh Dickins authored and torvalds committed Nov 20, 2008
1 parent 3fa59df commit 966c8c1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions kernel/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,24 @@ int sprint_symbol(char *buffer, unsigned long address)
char *modname;
const char *name;
unsigned long offset, size;
char namebuf[KSYM_NAME_LEN];
int len;

name = kallsyms_lookup(address, &size, &offset, &modname, namebuf);
name = kallsyms_lookup(address, &size, &offset, &modname, buffer);
if (!name)
return sprintf(buffer, "0x%lx", address);

if (name != buffer)
strcpy(buffer, name);
len = strlen(buffer);
buffer += len;

if (modname)
return sprintf(buffer, "%s+%#lx/%#lx [%s]", name, offset,
size, modname);
len += sprintf(buffer, "+%#lx/%#lx [%s]",
offset, size, modname);
else
return sprintf(buffer, "%s+%#lx/%#lx", name, offset, size);
len += sprintf(buffer, "+%#lx/%#lx", offset, size);

return len;
}

/* Look up a kernel symbol and print it to the kernel messages. */
Expand Down

0 comments on commit 966c8c1

Please sign in to comment.