[PATCH v1 1/2] vsprintf: Add %pR human-readable size
Bjorn Helgaas <[email protected]>
| Newsgroups | org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci |
|---|---|
| Message-ID | <[email protected]> |
Include human-readable size when printing struct resource memory ranges (not including DMA, bus number, or I/O port ranges) with the %pR format to make it easier to read, e.g., - pci 0000:00:02.0: BAR 0 [mem 0xfea80000-0xfea9ffff] + pci 0000:00:02.0: BAR 0 [mem 0xfea80000-0xfea9ffff (128 KiB)] Signed-off-by: Bjorn Helgaas <[email protected]> --- lib/vsprintf.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 2bc6ef483576..c49044b6dbee 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1094,15 +1094,17 @@ char *resource_string(char *buf, char *end, struct resource *res, /* 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) +#define RSRC_STR_SIZE sizeof(" (xxxx.xxx MiB)") #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) -#define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") -#define RAW_BUF_SIZE sizeof("[mem - flags 0x]") - char sym[MAX(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, - 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; +#define DECODED_BUF_SIZE sizeof("[mem - () 64bit pref window disabled]") +#define RAW_BUF_SIZE sizeof("[mem - () flags 0x]") + char sym[MAX(2*RSRC_BUF_SIZE + RSRC_STR_SIZE + DECODED_BUF_SIZE, + 2*RSRC_BUF_SIZE + RSRC_STR_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; char *p = sym, *pend = sym + sizeof(sym); bool decode = fmt[0] == 'R'; const struct printf_spec *specp; + char size_buf[32]; if (check_pointer(&buf, end, res, spec)) return buf; @@ -1134,6 +1136,14 @@ char *resource_string(char *buf, char *end, struct resource *res, } else { p = hex_range(p, pend, res->start, res->end, *specp); } + if (res->flags & IORESOURCE_MEM) { + *p++ = ' '; + *p++ = '('; + string_get_size(resource_size(res), 1, STRING_UNITS_2, + size_buf, sizeof(size_buf)); + p = string_nocheck(p, pend, size_buf, str_spec); + *p++ = ')'; + } if (decode) { if (res->flags & IORESOURCE_MEM_64) p = string_nocheck(p, pend, " 64bit", str_spec); -- 2.53.0