[PCIUTILS PATCH] Improve large BAR display

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



lspci currently displays anything larger than 2GB as a raw number.
I have a device with a larger BAR and wanted to see that reported as
a multiple of a GB.

I took the opportunity to rewrite this routine to make it easier to add
higher powers in the future.  It's also slightly shorter, which is nice.
I also changed it to use the binary prefixes, much as I dislike them
personally.

Signed-off-by: Matthew Wilcox <willy@xxxxxxxxxxxxxxx>

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
-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux