aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2010-03-05 12:47:37 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 20:53:07 -0500
commit4da0b66c6e9ea7ba78a19f9f186779826d89f8b0 (patch)
tree467fe1886f35dd199a7ba8b95ed5a06e2bfe83f3 /lib/vsprintf.c
parentb89dc5d6b0981c1096ccffbf8f4413c7bb1bcc0a (diff)
vsprintf: move %pR resource printf_specs off the stack
This adds separate I/O and memory specs, so we don't have to change the field width in a shared spec, which then lets us make all the specs const and static, since they never change. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index a900d136e643..0d461c7c14db 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -597,22 +597,29 @@ static char *resource_string(char *buf, char *end, struct resource *res,
597#ifndef MEM_RSRC_PRINTK_SIZE 597#ifndef MEM_RSRC_PRINTK_SIZE
598#define MEM_RSRC_PRINTK_SIZE 10 598#define MEM_RSRC_PRINTK_SIZE 10
599#endif 599#endif
600 struct printf_spec hex_spec = { 600 static const struct printf_spec io_spec = {
601 .base = 16, 601 .base = 16,
602 .field_width = IO_RSRC_PRINTK_SIZE,
602 .precision = -1, 603 .precision = -1,
603 .flags = SPECIAL | SMALL | ZEROPAD, 604 .flags = SPECIAL | SMALL | ZEROPAD,
604 }; 605 };
605 struct printf_spec dec_spec = { 606 static const struct printf_spec mem_spec = {
607 .base = 16,
608 .field_width = MEM_RSRC_PRINTK_SIZE,
609 .precision = -1,
610 .flags = SPECIAL | SMALL | ZEROPAD,
611 };
612 static const struct printf_spec dec_spec = {
606 .base = 10, 613 .base = 10,
607 .precision = -1, 614 .precision = -1,
608 .flags = 0, 615 .flags = 0,
609 }; 616 };
610 struct printf_spec str_spec = { 617 static const struct printf_spec str_spec = {
611 .field_width = -1, 618 .field_width = -1,
612 .precision = 10, 619 .precision = 10,
613 .flags = LEFT, 620 .flags = LEFT,
614 }; 621 };
615 struct printf_spec flag_spec = { 622 static const struct printf_spec flag_spec = {
616 .base = 16, 623 .base = 16,
617 .precision = -1, 624 .precision = -1,
618 .flags = SPECIAL | SMALL, 625 .flags = SPECIAL | SMALL,
@@ -628,35 +635,31 @@ static char *resource_string(char *buf, char *end, struct resource *res,
628 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; 635 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
629 636
630 char *p = sym, *pend = sym + sizeof(sym); 637 char *p = sym, *pend = sym + sizeof(sym);
631 int size = -1, addr = 0;
632 int decode = (fmt[0] == 'R') ? 1 : 0; 638 int decode = (fmt[0] == 'R') ? 1 : 0;
633 639 const struct printf_spec *specp;
634 if (res->flags & IORESOURCE_IO) {
635 size = IO_RSRC_PRINTK_SIZE;
636 addr = 1;
637 } else if (res->flags & IORESOURCE_MEM) {
638 size = MEM_RSRC_PRINTK_SIZE;
639 addr = 1;
640 }
641 640
642 *p++ = '['; 641 *p++ = '[';
643 if (res->flags & IORESOURCE_IO) 642 if (res->flags & IORESOURCE_IO) {
644 p = string(p, pend, "io ", str_spec); 643 p = string(p, pend, "io ", str_spec);
645 else if (res->flags & IORESOURCE_MEM) 644 specp = &io_spec;
645 } else if (res->flags & IORESOURCE_MEM) {
646 p = string(p, pend, "mem ", str_spec); 646 p = string(p, pend, "mem ", str_spec);
647 else if (res->flags & IORESOURCE_IRQ) 647 specp = &mem_spec;
648 } else if (res->flags & IORESOURCE_IRQ) {
648 p = string(p, pend, "irq ", str_spec); 649 p = string(p, pend, "irq ", str_spec);
649 else if (res->flags & IORESOURCE_DMA) 650 specp = &dec_spec;
651 } else if (res->flags & IORESOURCE_DMA) {
650 p = string(p, pend, "dma ", str_spec); 652 p = string(p, pend, "dma ", str_spec);
651 else { 653 specp = &dec_spec;
654 } else {
652 p = string(p, pend, "??? ", str_spec); 655 p = string(p, pend, "??? ", str_spec);
656 specp = &mem_spec;
653 decode = 0; 657 decode = 0;
654 } 658 }
655 hex_spec.field_width = size; 659 p = number(p, pend, res->start, *specp);
656 p = number(p, pend, res->start, addr ? hex_spec : dec_spec);
657 if (res->start != res->end) { 660 if (res->start != res->end) {
658 *p++ = '-'; 661 *p++ = '-';
659 p = number(p, pend, res->end, addr ? hex_spec : dec_spec); 662 p = number(p, pend, res->end, *specp);
660 } 663 }
661 if (decode) { 664 if (decode) {
662 if (res->flags & IORESOURCE_MEM_64) 665 if (res->flags & IORESOURCE_MEM_64)