diff mbox

[PCIUTILS] Improve large BAR display

Message ID 20091120213050.GB8502@parisc-linux.org (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Matthew Wilcox Nov. 20, 2009, 9:30 p.m. UTC
None
diff mbox

Patch

diff --git a/lspci.c b/lspci.c
index e453f1b..8685409 100644
--- a/lspci.c
+++ b/lspci.c
@@ -330,18 +330,16 @@  show_terse(struct device *d)
 static void
 show_size(pciaddr_t x)
 {
+  static const char suffix[][4] = { "", "KiB", "MiB", "GiB", "TiB" };
+  unsigned i;
   if (!x)
     return;
-  printf(" [size=");
-  if (x < 1024)
-    printf("%d", (int) x);
-  else if (x < 1048576)
-    printf("%dK", (int)(x / 1024));
-  else if (x < 0x80000000)
-    printf("%dM", (int)(x / 1048576));
-  else
-    printf(PCIADDR_T_FMT, x);
-  putchar(']');
+  for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
+    if (x < 1024)
+      break;
+    x /= 1024;
+  }
+  printf(" [size=%u%s]", (unsigned)x, suffix[i]);
 }
 
 static void