From patchwork Tue Oct 13 19:22:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 53508 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9DJYvIH013469 for ; Tue, 13 Oct 2009 19:35:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934203AbZJMTYA (ORCPT ); Tue, 13 Oct 2009 15:24:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S934113AbZJMTX6 (ORCPT ); Tue, 13 Oct 2009 15:23:58 -0400 Received: from g5t0008.atlanta.hp.com ([15.192.0.45]:17949 "EHLO g5t0008.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934188AbZJMTXz (ORCPT ); Tue, 13 Oct 2009 15:23:55 -0400 Received: from g1t0038.austin.hp.com (g1t0038.austin.hp.com [16.236.32.44]) by g5t0008.atlanta.hp.com (Postfix) with ESMTP id B5989249CB; Tue, 13 Oct 2009 19:22:05 +0000 (UTC) Received: from ldl (linux.corp.hp.com [15.11.146.101]) by g1t0038.austin.hp.com (Postfix) with ESMTP id 8187C300A5; Tue, 13 Oct 2009 19:22:05 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 72F22CF002A; Tue, 13 Oct 2009 13:22:05 -0600 (MDT) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i29GQFQUSZvh; Tue, 13 Oct 2009 13:22:05 -0600 (MDT) Received: from eh.fc.hp.com (eh.fc.hp.com [15.11.146.105]) by ldl (Postfix) with ESMTP id 5BD60CF0007; Tue, 13 Oct 2009 13:22:05 -0600 (MDT) Received: from bob.kio (localhost [127.0.0.1]) by eh.fc.hp.com (Postfix) with ESMTP id 48BAB26146; Tue, 13 Oct 2009 13:22:05 -0600 (MDT) Subject: [PATCH v2 2/9] vsprintf: add %pR support for IRQ and DMA resources To: Jesse Barnes From: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Yinghai Lu , Joe Perches , Len Brown Date: Tue, 13 Oct 2009 13:22:05 -0600 Message-ID: <20091013192205.22336.71607.stgit@bob.kio> In-Reply-To: <20091013192040.22336.84876.stgit@bob.kio> References: <20091013192040.22336.84876.stgit@bob.kio> User-Agent: StGit/0.14.3.386.gb02d MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org different from the start. Signed-off-by: Bjorn Helgaas --- lib/vsprintf.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 7830576..fcbe69d 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -604,28 +604,40 @@ 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, + }; + /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8) + * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */ +#define RSRC_BUF_SIZE ((2 * sizeof(resource_size_t)) + 4) + char sym[2*RSRC_BUF_SIZE + sizeof("[-]")]; 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; + *p = '\0'; return string(buf, end, sym, spec); }