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