From 2a69b50db6658189c337287aa47c5768f10cb197 Mon Sep 17 00:00:00 2001 From: Yang Bai Date: Fri, 10 Feb 2012 17:55:34 +0800 Subject: [PATCH] kvm tools: unite the error handle in kvm__init When error occurs, just set the ret to the reason, then jump to the error handle labels. This makes the code more readable. Signed-off-by: Yang Bai Signed-off-by: Pekka Enberg --- tools/kvm/kvm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 8e749ad99cd5..192d70eddf84 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -339,7 +339,8 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s if (!kvm__arch_cpu_supports_vm()) { pr_err("Your CPU does not support hardware virtualization"); - return ERR_PTR(-ENOSYS); + ret = -ENOSYS; + goto err; } kvm = kvm__new(); @@ -378,13 +379,13 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s kvm->name = strdup(name); if (!kvm->name) { ret = -ENOMEM; - goto err; + goto err_vm_fd; } if (kvm__check_extensions(kvm)) { pr_err("A required KVM extention is not supported by OS"); ret = -ENOSYS; - goto err; + goto err_vm_fd; } kvm__arch_init(kvm, hugetlbfs_path, ram_size); @@ -394,13 +395,13 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s return kvm; -err: +err_vm_fd: close(kvm->vm_fd); err_sys_fd: close(kvm->sys_fd); err_free: free(kvm); - +err: return ERR_PTR(ret); } -- 2.39.5