Blame SOURCES/0130-lscpu-cleanup-DMI-detection-return-codes.patch

05ad79
From 1b6deafbe0a671d4fd7b8b6e9cc23c8dfcd8683c Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Tue, 13 Jun 2017 12:15:11 +0200
05ad79
Subject: [PATCH 130/135] lscpu: cleanup DMI detection return codes
05ad79
05ad79
Michal wrote:
05ad79
 There is weird mix of logic in lscpu-dmi.c which sometimes returns 0 and
05ad79
 sometimes -1 on error. Since most checks are if (rc) goto done; this
05ad79
 bails out early on error skipping some detection methods. Further, in
05ad79
 lscpu.c all following detections are guarder by if(hyper) so returning
05ad79
 -1 causes all following methods to be skipped.
05ad79
05ad79
Upstream: http://github.com/karelzak/util-linux/commit/c972852b29391c35b1d5c7d3e1e6413e0cc86908
05ad79
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1468646
05ad79
Reported-by: Michal Suchanek <msuchanek@suse.de>
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 sys-utils/lscpu-dmi.c | 21 +++++++++++++--------
05ad79
 1 file changed, 13 insertions(+), 8 deletions(-)
05ad79
05ad79
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
05ad79
index a8298ff74..e4afd0b92 100644
05ad79
--- a/sys-utils/lscpu-dmi.c
05ad79
+++ b/sys-utils/lscpu-dmi.c
05ad79
@@ -172,7 +172,7 @@ done:
05ad79
 static int hypervisor_decode_legacy(uint8_t *buf, const char *devmem)
05ad79
 {
05ad79
 	if (!checksum(buf, 0x0F))
05ad79
-		return HYPER_NONE;
05ad79
+		return -1;
05ad79
 
05ad79
 	return hypervisor_from_dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06),
05ad79
 			 WORD(buf + 0x0C),
05ad79
@@ -252,11 +252,15 @@ int read_hypervisor_dmi(void)
05ad79
 	    || sizeof(uint16_t) != 2
05ad79
 	    || sizeof(uint32_t) != 4
05ad79
 	    || '\0' != 0)
05ad79
-		return rc;
05ad79
+		goto done;
05ad79
 
05ad79
+	/* -1 : no DMI in /sys,
05ad79
+	 *  0 : DMI exist, nothing detected (HYPER_NONE)
05ad79
+	 * >0 : hypervisor detected
05ad79
+	 */
05ad79
 	rc = hypervisor_decode_sysfw();
05ad79
-	if (rc >= 0)
05ad79
-		return rc;
05ad79
+	if (rc >= HYPER_NONE)
05ad79
+		goto done;
05ad79
 
05ad79
 	/* First try EFI (ia64, Intel-based Mac) */
05ad79
 	switch (address_from_efi(&fp)) {
05ad79
@@ -271,8 +275,9 @@ int read_hypervisor_dmi(void)
05ad79
 		goto done;
05ad79
 
05ad79
 	rc = hypervisor_decode_smbios(buf, _PATH_DEV_MEM);
05ad79
-	if (rc)
05ad79
+	if (rc >= HYPER_NONE)
05ad79
 		goto done;
05ad79
+
05ad79
 	free(buf);
05ad79
 	buf = NULL;
05ad79
 memory_scan:
05ad79
@@ -285,17 +290,17 @@ memory_scan:
05ad79
 	for (fp = 0; fp <= 0xFFF0; fp += 16) {
05ad79
 		if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
05ad79
 			rc = hypervisor_decode_smbios(buf + fp, _PATH_DEV_MEM);
05ad79
-			if (rc == -1)
05ad79
+			if (rc < 0)
05ad79
 				fp += 16;
05ad79
 
05ad79
 		} else if (memcmp(buf + fp, "_DMI_", 5) == 0)
05ad79
 			rc = hypervisor_decode_legacy(buf + fp, _PATH_DEV_MEM);
05ad79
 
05ad79
-		if (rc >= 0)
05ad79
+		if (rc >= HYPER_NONE)
05ad79
 			break;
05ad79
 	}
05ad79
 #endif
05ad79
 done:
05ad79
 	free(buf);
05ad79
-	return rc;
05ad79
+	return rc < 0 ? HYPER_NONE : rc;
05ad79
 }
05ad79
-- 
05ad79
2.13.6
05ad79