All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trent Piepho <xyzzy@speakeasy.org>
To: linux-kernel@vger.kernel.org
Cc: torvalds@linux-foundation.org, Trent Piepho <xyzzy@speakeasy.org>
Subject: [PATCH] printk: Let %pR handle NULL pointers
Date: Sat,  3 Jan 2009 02:42:21 -0800	[thread overview]
Message-ID: <1230979341-23029-1-git-send-email-xyzzy@speakeasy.org> (raw)

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


             reply	other threads:[~2009-01-03 10:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-03 10:42 Trent Piepho [this message]
2009-01-03 17:10 ` [PATCH] printk: Let %pR handle NULL pointers 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

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=1230979341-23029-1-git-send-email-xyzzy@speakeasy.org \
    --to=xyzzy@speakeasy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 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.