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>

authored by Bjorn Helgaas and committed by Linus Torvalds 4da0b66c b89dc5d6

+24 -21
+24 -21
lib/vsprintf.c
··· 597 597 #ifndef MEM_RSRC_PRINTK_SIZE 598 598 #define MEM_RSRC_PRINTK_SIZE 10 599 599 #endif 600 - struct printf_spec hex_spec = { 600 + static const struct printf_spec io_spec = { 601 601 .base = 16, 602 + .field_width = IO_RSRC_PRINTK_SIZE, 602 603 .precision = -1, 603 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 613 .base = 10, 607 614 .precision = -1, 608 615 .flags = 0, 609 616 }; 610 - struct printf_spec str_spec = { 617 + static const struct printf_spec str_spec = { 611 618 .field_width = -1, 612 619 .precision = 10, 613 620 .flags = LEFT, 614 621 }; 615 - struct printf_spec flag_spec = { 622 + static const struct printf_spec flag_spec = { 616 623 .base = 16, 617 624 .precision = -1, 618 625 .flags = SPECIAL | SMALL, ··· 635 628 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; 636 629 637 630 char *p = sym, *pend = sym + sizeof(sym); 638 - int size = -1, addr = 0; 639 631 int decode = (fmt[0] == 'R') ? 1 : 0; 640 - 641 - if (res->flags & IORESOURCE_IO) { 642 - size = IO_RSRC_PRINTK_SIZE; 643 - addr = 1; 644 - } else if (res->flags & IORESOURCE_MEM) { 645 - size = MEM_RSRC_PRINTK_SIZE; 646 - addr = 1; 647 - } 632 + const struct printf_spec *specp; 648 633 649 634 *p++ = '['; 650 - if (res->flags & IORESOURCE_IO) 635 + if (res->flags & IORESOURCE_IO) { 651 636 p = string(p, pend, "io ", str_spec); 652 - else if (res->flags & IORESOURCE_MEM) 637 + specp = &io_spec; 638 + } else if (res->flags & IORESOURCE_MEM) { 653 639 p = string(p, pend, "mem ", str_spec); 654 - else if (res->flags & IORESOURCE_IRQ) 640 + specp = &mem_spec; 641 + } else if (res->flags & IORESOURCE_IRQ) { 655 642 p = string(p, pend, "irq ", str_spec); 656 - else if (res->flags & IORESOURCE_DMA) 643 + specp = &dec_spec; 644 + } else if (res->flags & IORESOURCE_DMA) { 657 645 p = string(p, pend, "dma ", str_spec); 658 - else { 646 + specp = &dec_spec; 647 + } else { 659 648 p = string(p, pend, "??? ", str_spec); 649 + specp = &mem_spec; 660 650 decode = 0; 661 651 } 662 - hex_spec.field_width = size; 663 - p = number(p, pend, res->start, addr ? hex_spec : dec_spec); 652 + p = number(p, pend, res->start, *specp); 664 653 if (res->start != res->end) { 665 654 *p++ = '-'; 666 - p = number(p, pend, res->end, addr ? hex_spec : dec_spec); 655 + p = number(p, pend, res->end, *specp); 667 656 } 668 657 if (decode) { 669 658 if (res->flags & IORESOURCE_MEM_64)