aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2009-10-27 15:26:47 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-11-04 16:06:41 -0500
commitc7dabef8a2c59e6a3de9d66fc35fb6a43ef7172d (patch)
tree0f8b0021e693a0e380ef9026083b59d0909dffc6 /lib
parent4fd8bdc567e70c02fab7eeaaa7d2a64232add789 (diff)
vsprintf: use %pR, %pr instead of %pRt, %pRf
Jesse accidentally applied v1 [1] of the patchset instead of v2 [2]. This is the diff between v1 and v2. The changes in this patch are: - tidied vsprintf stack buffer to shrink and compute size more accurately - use %pR for decoding and %pr for "raw" (with type and flags) instead of adding %pRt and %pRf [1] http://lkml.org/lkml/2009/10/6/491 [2] http://lkml.org/lkml/2009/10/13/441 Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index a6e195163eb3..6438cd5599ee 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -624,13 +624,19 @@ static char *resource_string(char *buf, char *end, struct resource *res,
624 .precision = -1, 624 .precision = -1,
625 .flags = SPECIAL | SMALL, 625 .flags = SPECIAL | SMALL,
626 }; 626 };
627 /* 627
628 * room for three actual numbers (decimal or hex), plus 628 /* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8)
629 * "[mem 0x-0x 64bit pref disabled flags 0x]\0" 629 * 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */
630 */ 630#define RSRC_BUF_SIZE ((2 * sizeof(resource_size_t)) + 4)
631 char sym[3*3*sizeof(resource_size_t) + 41]; 631#define FLAG_BUF_SIZE (2 * sizeof(res->flags))
632#define DECODED_BUF_SIZE sizeof("[mem - 64bit pref disabled]")
633#define RAW_BUF_SIZE sizeof("[mem - flags 0x]")
634 char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE,
635 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
636
632 char *p = sym, *pend = sym + sizeof(sym); 637 char *p = sym, *pend = sym + sizeof(sym);
633 int size = -1, addr = 0; 638 int size = -1, addr = 0;
639 int decode = (fmt[0] == 'R') ? 1 : 0;
634 640
635 if (res->flags & IORESOURCE_IO) { 641 if (res->flags & IORESOURCE_IO) {
636 size = IO_RSRC_PRINTK_SIZE; 642 size = IO_RSRC_PRINTK_SIZE;
@@ -641,15 +647,17 @@ static char *resource_string(char *buf, char *end, struct resource *res,
641 } 647 }
642 648
643 *p++ = '['; 649 *p++ = '[';
644 if (fmt[1] == 't' || fmt[1] == 'f') { 650 if (res->flags & IORESOURCE_IO)
645 if (res->flags & IORESOURCE_IO) 651 p = string(p, pend, "io ", str_spec);
646 p = string(p, pend, "io ", str_spec); 652 else if (res->flags & IORESOURCE_MEM)
647 else if (res->flags & IORESOURCE_MEM) 653 p = string(p, pend, "mem ", str_spec);
648 p = string(p, pend, "mem ", str_spec); 654 else if (res->flags & IORESOURCE_IRQ)
649 else if (res->flags & IORESOURCE_IRQ) 655 p = string(p, pend, "irq ", str_spec);
650 p = string(p, pend, "irq ", str_spec); 656 else if (res->flags & IORESOURCE_DMA)
651 else if (res->flags & IORESOURCE_DMA) 657 p = string(p, pend, "dma ", str_spec);
652 p = string(p, pend, "dma ", str_spec); 658 else {
659 p = string(p, pend, "??? ", str_spec);
660 decode = 0;
653 } 661 }
654 hex_spec.field_width = size; 662 hex_spec.field_width = size;
655 p = number(p, pend, res->start, addr ? hex_spec : dec_spec); 663 p = number(p, pend, res->start, addr ? hex_spec : dec_spec);
@@ -657,21 +665,19 @@ static char *resource_string(char *buf, char *end, struct resource *res,
657 *p++ = '-'; 665 *p++ = '-';
658 p = number(p, pend, res->end, addr ? hex_spec : dec_spec); 666 p = number(p, pend, res->end, addr ? hex_spec : dec_spec);
659 } 667 }
660 if (fmt[1] == 't' || fmt[1] == 'f') { 668 if (decode) {
661 if (res->flags & IORESOURCE_MEM_64) 669 if (res->flags & IORESOURCE_MEM_64)
662 p = string(p, pend, " 64bit", str_spec); 670 p = string(p, pend, " 64bit", str_spec);
663 if (res->flags & IORESOURCE_PREFETCH) 671 if (res->flags & IORESOURCE_PREFETCH)
664 p = string(p, pend, " pref", str_spec); 672 p = string(p, pend, " pref", str_spec);
665 if (res->flags & IORESOURCE_DISABLED) 673 if (res->flags & IORESOURCE_DISABLED)
666 p = string(p, pend, " disabled", str_spec); 674 p = string(p, pend, " disabled", str_spec);
667 if (fmt[1] == 'f') { 675 } else {
668 p = string(p, pend, " flags ", str_spec); 676 p = string(p, pend, " flags ", str_spec);
669 p = number(p, pend, res->flags & ~IORESOURCE_TYPE_BITS, 677 p = number(p, pend, res->flags, flag_spec);
670 flag_spec);
671 }
672 } 678 }
673 *p++ = ']'; 679 *p++ = ']';
674 *p = 0; 680 *p = '\0';
675 681
676 return string(buf, end, sym, spec); 682 return string(buf, end, sym, spec);
677} 683}
@@ -847,10 +853,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
847 * - 'f' For simple symbolic function names without offset 853 * - 'f' For simple symbolic function names without offset
848 * - 'S' For symbolic direct pointers with offset 854 * - 'S' For symbolic direct pointers with offset
849 * - 's' For symbolic direct pointers without offset 855 * - 's' For symbolic direct pointers without offset
850 * - 'R' For a struct resource pointer, print: 856 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
851 * R address range only ([0x0-0x1f]) 857 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
852 * Rt type and range ([mem 0x0-0x1f 64bit pref])
853 * Rf type, range, and flags ([mem 0x0-0x1f 64bit pref flags 0x1])
854 * - 'M' For a 6-byte MAC address, it prints the address in the 858 * - 'M' For a 6-byte MAC address, it prints the address in the
855 * usual colon-separated hex notation 859 * usual colon-separated hex notation
856 * - 'm' For a 6-byte MAC address, it prints the hex address without colons 860 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
@@ -881,6 +885,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
881 case 'S': 885 case 'S':
882 return symbol_string(buf, end, ptr, spec, *fmt); 886 return symbol_string(buf, end, ptr, spec, *fmt);
883 case 'R': 887 case 'R':
888 case 'r':
884 return resource_string(buf, end, ptr, spec, fmt); 889 return resource_string(buf, end, ptr, spec, fmt);
885 case 'M': /* Colon separated: 00:01:02:03:04:05 */ 890 case 'M': /* Colon separated: 00:01:02:03:04:05 */
886 case 'm': /* Contiguous: 000102030405 */ 891 case 'm': /* Contiguous: 000102030405 */