Re: Crash with kfree(null) on MacBook? kobject_set_name_vargs

From: Linus Torvalds
Date: Mon Apr 11 2011 - 13:49:03 EST


2011/4/11 Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>:
>
> prints out NULL is because the string printout code does this:
>
>        if ((unsigned long)s < PAGE_SIZE)
>                s = "(null)";
>
> which admittedly is not very helpful in this case (but it's usually
> nicer than just oopsing).

You could try this (UNTESTED!) patch to avoid this particular issue.
It will (well, unless I screwed up) print non-NULL pointers as the hex
value they have. So you should see "0x202" instead of "(null)" in that
case.

Of course, it sounds like _you_ don't actually see the bug at all,
because for you it probably really _is_ NULL. The people who see the
bug have some random non-null value, probably because of the field
just not being initialized properly, and containing some crud.

Linus
lib/vsprintf.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index bc0ac6b333dc..dabc310684bf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -400,8 +400,14 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec)
{
int len, i;

- if ((unsigned long)s < PAGE_SIZE)
+ if ((unsigned long)s < PAGE_SIZE) {
+ if (s) {
+ spec.base = 16;
+ spec.flags |= SPECIAL;
+ return number(buf, end, (unsigned long)s, spec);
+ }
s = "(null)";
+ }

len = strnlen(s, spec.precision);