Blame SOURCES/0017-dmidecode-Use-the-print-helpers-in-dump-mode-too.patch

fc71ac
From da06888d08b9f1108fe89560c06d39675c10cd95 Mon Sep 17 00:00:00 2001
fc71ac
From: Jean Delvare <jdelvare@suse.de>
fc71ac
Date: Wed, 1 Apr 2020 10:00:30 +0200
fc71ac
Subject: [PATCH 17/23] dmidecode: Use the print helpers in dump mode too
fc71ac
fc71ac
Signed-off-by: Jean Delvare <jdelvare@suse.de>
fc71ac
---
fc71ac
 dmidecode.c | 30 ++++++++++++++++++------------
fc71ac
 1 file changed, 18 insertions(+), 12 deletions(-)
fc71ac
fc71ac
diff --git a/dmidecode.c b/dmidecode.c
fc71ac
index 3d1da955bab8..5e9b9899ec1f 100644
fc71ac
--- a/dmidecode.c
fc71ac
+++ b/dmidecode.c
fc71ac
@@ -220,43 +220,49 @@ static int dmi_bcd_range(u8 value, u8 low, u8 high)
fc71ac
 	return 1;
fc71ac
 }
fc71ac
 
fc71ac
-static void dmi_dump(const struct dmi_header *h, const char *prefix)
fc71ac
+static void dmi_dump(const struct dmi_header *h)
fc71ac
 {
fc71ac
+	static char raw_data[48];
fc71ac
 	int row, i;
fc71ac
+	unsigned int off;
fc71ac
 	char *s;
fc71ac
 
fc71ac
-	printf("%sHeader and Data:\n", prefix);
fc71ac
+	pr_list_start("Header and Data", NULL);
fc71ac
 	for (row = 0; row < ((h->length - 1) >> 4) + 1; row++)
fc71ac
 	{
fc71ac
-		printf("%s\t", prefix);
fc71ac
+		off = 0;
fc71ac
 		for (i = 0; i < 16 && i < h->length - (row << 4); i++)
fc71ac
-			printf("%s%02X", i ? " " : "",
fc71ac
+			off += sprintf(raw_data + off, i ? " %02X" : "%02X",
fc71ac
 			       (h->data)[(row << 4) + i]);
fc71ac
-		printf("\n");
fc71ac
+		pr_list_item(raw_data);
fc71ac
 	}
fc71ac
+	pr_list_end();
fc71ac
 
fc71ac
 	if ((h->data)[h->length] || (h->data)[h->length + 1])
fc71ac
 	{
fc71ac
-		printf("%sStrings:\n", prefix);
fc71ac
+		pr_list_start("Strings", NULL);
fc71ac
 		i = 1;
fc71ac
 		while ((s = _dmi_string(h, i++, !(opt.flags & FLAG_DUMP))))
fc71ac
 		{
fc71ac
 			if (opt.flags & FLAG_DUMP)
fc71ac
 			{
fc71ac
 				int j, l = strlen(s) + 1;
fc71ac
+
fc71ac
+				off = 0;
fc71ac
 				for (row = 0; row < ((l - 1) >> 4) + 1; row++)
fc71ac
 				{
fc71ac
-					printf("%s\t", prefix);
fc71ac
 					for (j = 0; j < 16 && j < l - (row << 4); j++)
fc71ac
-						printf("%s%02X", j ? " " : "",
fc71ac
+						off += sprintf(raw_data + off,
fc71ac
+						       j ? " %02X" : "%02X",
fc71ac
 						       (unsigned char)s[(row << 4) + j]);
fc71ac
-					printf("\n");
fc71ac
+					pr_list_item(raw_data);
fc71ac
 				}
fc71ac
 				/* String isn't filtered yet so do it now */
fc71ac
 				ascii_filter(s, l - 1);
fc71ac
 			}
fc71ac
-			printf("%s\t%s\n", prefix, s);
fc71ac
+			pr_list_item("%s", s);
fc71ac
 		}
fc71ac
+		pr_list_end();
fc71ac
 	}
fc71ac
 }
fc71ac
 
fc71ac
@@ -5060,7 +5066,7 @@ static void dmi_decode(const struct dmi_header *h, u16 ver)
fc71ac
 				return;
fc71ac
 			pr_handle_name("%s Type",
fc71ac
 				h->type >= 128 ? "OEM-specific" : "Unknown");
fc71ac
-			dmi_dump(h, "\t");
fc71ac
+			dmi_dump(h);
fc71ac
 	}
fc71ac
 	printf("\n");
fc71ac
 }
fc71ac
@@ -5206,7 +5212,7 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
fc71ac
 		{
fc71ac
 			if (opt.flags & FLAG_DUMP)
fc71ac
 			{
fc71ac
-				dmi_dump(&h, "\t");
fc71ac
+				dmi_dump(&h);
fc71ac
 				printf("\n");
fc71ac
 			}
fc71ac
 			else
fc71ac
-- 
fc71ac
2.17.1
fc71ac