]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: fix read_hypervisor_powerpc() logic
authorKarel Zak <kzak@redhat.com>
Tue, 1 Sep 2015 10:37:18 +0000 (12:37 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 1 Sep 2015 10:37:18 +0000 (12:37 +0200)
We care about /proc/device-tree/compatible content...

The patch also removes unnecessary path_exist(), it seems good enough
to call open() rather than access() + open().

Addresses: https://github.com/karelzak/util-linux/issues/218
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index 1f8f5f19804a41e2d8fd4b15d2bc49b8834f6562..47f690d883708437b3e584877136583898a4c91c 100644 (file)
@@ -603,9 +603,8 @@ read_hypervisor_cpuid(struct lscpu_desc *desc __attribute__((__unused__)))
 
 static int is_compatible(const char *path, const char *str)
 {
-       FILE *fd;
+       FILE *fd = path_fopen("r", 0, "%s", path);
 
-       fd = path_fopen("r", 0, "%s", path);
        if (fd) {
                char buf[256];
                size_t i, len;
@@ -636,11 +635,9 @@ read_hypervisor_powerpc(struct lscpu_desc *desc)
                desc->virtype = VIRT_PARA;
 
        /* PowerNV (POWER Non-Virtualized, bare-metal) */
-       } else if (path_exist(_PATH_PROC_DEVICETREE "/compatible")) {
-               if (is_compatible(_PATH_PROC_DEVICETREE "/compatible", "ibm,powernv")) {
-                       desc->hyper = HYPER_NONE;
-                       desc->virtype = VIRT_NONE;
-               }
+       } else if (is_compatible(_PATH_PROC_DEVICETREE "/compatible", "ibm,powernv")) {
+               desc->hyper = HYPER_NONE;
+               desc->virtype = VIRT_NONE;
 
        /* PowerVM (IBM's proprietary hypervisor, aka pHyp) */
        } else if (path_exist(_PATH_PROC_DEVICETREE "/ibm,partition-name")
@@ -658,11 +655,9 @@ read_hypervisor_powerpc(struct lscpu_desc *desc)
                }
 
        /* Qemu */
-       } else if (path_exist(_PATH_PROC_DEVICETREE "/compatible")) {
-               if (is_compatible(_PATH_PROC_DEVICETREE "/compatible", "qemu,pseries")) {
-                       desc->hyper = HYPER_KVM;
-                       desc->virtype = VIRT_PARA;
-               }
+       } else if (is_compatible(_PATH_PROC_DEVICETREE "/compatible", "qemu,pseries")) {
+               desc->hyper = HYPER_KVM;
+               desc->virtype = VIRT_PARA;
        }
        return desc->hyper;
 }