File util-linux-lscpu-dmi-return-0-when-something-fails.patch of Package util-linux.7828
From 2cdd8ae3bf2fc978e34a930c2179fd179c503435 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Thu, 8 Jun 2017 18:58:06 +0200
Subject: [PATCH] lscpu: dmi: return 0 when something fails
There is weird mix of logic in lscpu-dmi.c which sometimes returns 0 and
sometimes -1 on error. Since most checks are if (rc) goto done; this
bails out early on error skipping some detection methods. Further, in
lscpu.c all following detections are guarder by if(hyper) so returnning
-1 causes all following methods to be skipped.
Some users observe that they are running under hypervisor and this is
not detected so it is probably good idea to just try everything.
On the other hand, some users reported in the past that the wrong
detection method crashed their system so there is potential for
regression.
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
sys-utils/lscpu-dmi.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index 3ba999124a2e..71d6874c919d 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -187,7 +187,7 @@ static int hypervisor_decode_smbios(uint8_t *buf, const char *devmem)
if (!checksum(buf, buf[0x05])
|| memcmp(buf + 0x10, "_DMI_", 5) != 0
|| !checksum(buf + 0x10, 0x0F))
- return -1;
+ return HYPER_NONE;
return hypervisor_from_dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16),
WORD(buf + 0x1C),
@@ -200,7 +200,7 @@ static int hypervisor_decode_sysfw(void)
struct stat st;
if (stat(sys_fw_dmi_tables, &st))
- return -1;
+ return HYPER_NONE;
return hypervisor_from_dmi_table(0, st.st_size, st.st_size / 4,
sys_fw_dmi_tables);
@@ -257,7 +257,7 @@ int read_hypervisor_dmi(void)
return rc;
rc = hypervisor_decode_sysfw();
- if (rc >= 0)
+ if (rc > HYPER_NONE)
return rc;
/* First try EFI (ia64, Intel-based Mac) */
@@ -273,7 +273,7 @@ int read_hypervisor_dmi(void)
goto done;
rc = hypervisor_decode_smbios(buf, _PATH_DEV_MEM);
- if (rc)
+ if (rc > HYPER_NONE)
goto done;
free(buf);
buf = NULL;
@@ -287,13 +287,13 @@ memory_scan:
for (fp = 0; fp <= 0xFFF0; fp += 16) {
if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
rc = hypervisor_decode_smbios(buf + fp, _PATH_DEV_MEM);
- if (rc == -1)
+ if ( ! (rc > HYPER_NONE))
fp += 16;
} else if (memcmp(buf + fp, "_DMI_", 5) == 0)
rc = hypervisor_decode_legacy(buf + fp, _PATH_DEV_MEM);
- if (rc >= 0)
+ if (rc > HYPER_NONE)
break;
}
#endif
--
2.10.2