All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] printk: Let %pR handle NULL pointers
@ 2009-01-03 10:42 Trent Piepho
  2009-01-03 17:10 ` Linus Torvalds
  0 siblings, 1 reply; 9+ messages in thread
From: Trent Piepho @ 2009-01-03 10:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: torvalds, Trent Piepho

Have %pR print "[NULL]" for the resource range when passed a NULL pointer.

Trying to print a NULL pointer with %pR crashes, though printing a NULL
pointer with %p works fine.  It isn't very helpful to put in a dev_dbg() to
print a resource and have the kernel crash because sometimes the resource
can be NULL.

Printing "[NULL]" is more useful than crashing when the resource isn't
supposed to be NULL and simplifies code in cases where one wants to print a
resource range than is allowed to be NULL.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
---
 lib/vsprintf.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3b77702..2879a1b 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -566,6 +566,9 @@ static char *resource_string(char *buf, char *end, struct resource *res, int fie
 	char *p = sym, *pend = sym + sizeof(sym);
 	int size = -1;
 
+	if (!res)
+		return string(buf, end, "[NULL]", field_width, precision, flags);
+
 	if (res->flags & IORESOURCE_IO)
 		size = IO_RSRC_PRINTK_SIZE;
 	else if (res->flags & IORESOURCE_MEM)
-- 
1.5.4.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-01-04 20:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-03 10:42 [PATCH] printk: Let %pR handle NULL pointers Trent Piepho
2009-01-03 17:10 ` Linus Torvalds
2009-01-03 19:33   ` Harvey Harrison
2009-01-03 21:53   ` Benjamin Herrenschmidt
2009-01-04  5:02     ` Trent Piepho
2009-01-04  5:14       ` Valdis.Kletnieks
2009-01-04  9:31         ` Johannes Berg
2009-01-04  9:48       ` Benjamin Herrenschmidt
2009-01-04 20:41         ` Trent Piepho

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.