]> mj.ucw.cz Git - pciutils.git/blobdiff - lspci.c
Released as 3.1.5.
[pciutils.git] / lspci.c
diff --git a/lspci.c b/lspci.c
index e453f1bfb23d1855c559175db3319d0f4c56163b..54317cf5002f3395b8fad76ca0ce87bc88dfafa5 100644 (file)
--- 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[][2] = { "", "K", "M", "G", "T" };
+  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