From: Bjorn Helgaas <helgaas@kernel.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Petr Mladek" <pmladek@suse.com>,
"Steven Rostedt" <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Bjorn Helgaas <bhelgaas@google.com>
Subject: [PATCH v1 1/2] vsprintf: Add %pR human-readable size
Date: Sat, 8 Aug 2026 12:23:07 -0500 [thread overview]
Message-ID: <20260808172308.282591-2-bhelgaas@google.com> (raw)
In-Reply-To: <20260808172308.282591-1-bhelgaas@google.com>
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 <bhelgaas@google.com>
---
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
next prev parent reply other threads:[~2026-08-08 17:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 17:23 [PATCH v1 0/2] PCI: Include human-readable BAR and window sizes Bjorn Helgaas
2026-08-08 17:23 ` Bjorn Helgaas [this message]
2026-08-08 17:38 ` [PATCH v1 1/2] vsprintf: Add %pR human-readable size sashiko-bot
2026-08-08 17:43 ` Andy Shevchenko
2026-08-08 23:45 ` Bjorn Helgaas
2026-08-09 8:25 ` Andy Shevchenko
2026-08-08 17:23 ` [PATCH v1 2/2] PCI: Include human-readable sizes in resource assignment messages Bjorn Helgaas
2026-08-08 17:27 ` sashiko-bot
2026-08-08 17:48 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260808172308.282591-2-bhelgaas@google.com \
--to=helgaas@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.