]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: unite the error handle in kvm__init
authorYang Bai <hamo.by@gmail.com>
Fri, 10 Feb 2012 09:55:34 +0000 (17:55 +0800)
committerPekka Enberg <penberg@kernel.org>
Fri, 10 Feb 2012 11:37:18 +0000 (13:37 +0200)
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 <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm.c

index 8e749ad99cd59ea98acb1769c490c3f134c88d5d..192d70eddf84e963c57db248aea3191ab34d2ee5 100644 (file)
@@ -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);
 }