linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org
Subject: [PATCH 2/7] vsprintf: add %pR support for IRQ and DMA resources
Date: Tue, 06 Oct 2009 15:33:34 -0600	[thread overview]
Message-ID: <20091006213334.4272.31517.stgit@bob.kio> (raw)
In-Reply-To: <20091006213259.4272.68068.stgit@bob.kio>

Print addresses (IO port numbers and memory addresses) in hex, but print
others (IRQs and DMA channels) in decimal.  Only print the end if it's
different from the start.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
---
 lib/vsprintf.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7830576..1b60aed 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -604,26 +604,37 @@ static char *resource_string(char *buf, char *end, struct resource *res,
 #ifndef MEM_RSRC_PRINTK_SIZE
 #define MEM_RSRC_PRINTK_SIZE	10
 #endif
-	struct printf_spec num_spec = {
+	struct printf_spec hex_spec = {
 		.base = 16,
 		.precision = -1,
 		.flags = SPECIAL | SMALL | ZEROPAD,
 	};
-	/* room for the actual numbers, the two "0x", -, [, ] and the final zero */
-	char sym[4*sizeof(resource_size_t) + 8];
+	struct printf_spec dec_spec = {
+		.base = 10,
+		.precision = -1,
+		.flags = 0,
+	};
+	/* room for two actual numbers (decimal or hex), the two "0x", -, [, ]
+	 * and the final zero */
+	char sym[2*3*sizeof(resource_size_t) + 8];
 	char *p = sym, *pend = sym + sizeof(sym);
-	int size = -1;
+	int size = -1, addr = 0;
 
-	if (res->flags & IORESOURCE_IO)
+	if (res->flags & IORESOURCE_IO) {
 		size = IO_RSRC_PRINTK_SIZE;
-	else if (res->flags & IORESOURCE_MEM)
+		addr = 1;
+	} else if (res->flags & IORESOURCE_MEM) {
 		size = MEM_RSRC_PRINTK_SIZE;
+		addr = 1;
+	}
 
 	*p++ = '[';
-	num_spec.field_width = size;
-	p = number(p, pend, res->start, num_spec);
-	*p++ = '-';
-	p = number(p, pend, res->end, num_spec);
+	hex_spec.field_width = size;
+	p = number(p, pend, res->start, addr ? hex_spec : dec_spec);
+	if (res->start != res->end) {
+		*p++ = '-';
+		p = number(p, pend, res->end, addr ? hex_spec : dec_spec);
+	}
 	*p++ = ']';
 	*p = 0;
 

  parent reply	other threads:[~2009-10-06 21:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-06 21:33 [PATCH 0/7] PCI, PNP: print resources consistently Bjorn Helgaas
2009-10-06 21:33 ` [PATCH 1/7] vsprintf: fix io/mem resource width Bjorn Helgaas
2009-10-26 20:40   ` Jesse Barnes
2009-10-06 21:33 ` Bjorn Helgaas [this message]
2009-10-06 21:33 ` [PATCH 3/7] vsprintf: add %pRt, %pRf to print struct resource details Bjorn Helgaas
2009-10-06 21:33 ` [PATCH 4/7] PCI: print resources consistently with %pRt Bjorn Helgaas
2009-10-06 21:33 ` [PATCH 5/7] x86/PCI: " Bjorn Helgaas
2009-10-07 18:43   ` Yinghai Lu
2009-10-07 19:15     ` Bjorn Helgaas
2009-10-09 21:14       ` Len Brown
2009-10-10 15:36         ` Bjorn Helgaas
2009-10-06 21:33 ` [PATCH 6/7] ia64/PCI: " Bjorn Helgaas
2009-10-06 21:34 ` [PATCH 7/7] PNP: " Bjorn Helgaas

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=20091006213334.4272.31517.stgit@bob.kio \
    --to=bjorn.helgaas@hp.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).