Blame SOURCES/0156-util-Use-SZ_-size-macros-in-display-size.patch

e0018b
From e1c629bb3e01e3df24c189c0ecabde37788139a2 Mon Sep 17 00:00:00 2001
e0018b
From: Dan Williams <dan.j.williams@intel.com>
e0018b
Date: Thu, 28 Apr 2022 15:10:11 -0700
e0018b
Subject: [PATCH 156/217] util: Use SZ_ size macros in display size
e0018b
e0018b
In preparation for adding "Terabyte" support, cleanup the "1024"
e0018b
multiplication with the SZ_* macros.
e0018b
e0018b
Link: https://lore.kernel.org/r/165118381109.1676208.8857362319985041575.stgit@dwillia2-desk3.amr.corp.intel.com
e0018b
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 util/json.c | 11 ++++++-----
e0018b
 1 file changed, 6 insertions(+), 5 deletions(-)
e0018b
e0018b
diff --git a/util/json.c b/util/json.c
e0018b
index f8cc81f..ebdf8d9 100644
e0018b
--- a/util/json.c
e0018b
+++ b/util/json.c
e0018b
@@ -5,6 +5,7 @@
e0018b
 #include <stdio.h>
e0018b
 #include <util/util.h>
e0018b
 #include <util/json.h>
e0018b
+#include <util/size.h>
e0018b
 #include <json-c/json.h>
e0018b
 #include <json-c/printbuf.h>
e0018b
 
e0018b
@@ -27,24 +28,24 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
e0018b
 	 * If prefix == JEDEC, we mean prefixes like kilo,mega,giga etc.
e0018b
 	 */
e0018b
 
e0018b
-	if (bytes < 5000*1024)
e0018b
+	if (bytes < 5000*SZ_1K)
e0018b
 		snprintf(buf, sizeof(buf), "%lld", bytes);
e0018b
 	else {
e0018b
 		/* IEC */
e0018b
-		if (bytes < 2*1024LL*1024LL*1024LL) {
e0018b
-			long cMiB = (bytes * 200LL / (1LL<<20) +1) /2;
e0018b
+		if (bytes < 2L*SZ_1G) {
e0018b
+			long cMiB = (bytes * 200LL / SZ_1M+1) /2;
e0018b
 
e0018b
 			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld MiB",
e0018b
 					cMiB/100 , cMiB % 100);
e0018b
 		} else {
e0018b
-			long cGiB = (bytes * 200LL / (1LL<<30) +1) /2;
e0018b
+			long cGiB = (bytes * 200LL / SZ_1G+1) /2;
e0018b
 
e0018b
 			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld GiB",
e0018b
 					cGiB/100 , cGiB % 100);
e0018b
 		}
e0018b
 
e0018b
 		/* JEDEC */
e0018b
-		if (bytes < 2*1024LL*1024LL*1024LL) {
e0018b
+		if (bytes < 2L*SZ_1G) {
e0018b
 			long cMB  = (bytes / (1000000LL / 200LL) + 1) / 2;
e0018b
 
e0018b
 			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld MB)\"",
e0018b
-- 
e0018b
2.27.0
e0018b