[PATCH] printk: Let %pR handle NULL pointers

From: Trent Piepho
Date: Sat Jan 03 2009 - 05:42:29 EST


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@xxxxxxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/