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>
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();
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);
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);
}