kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm tool: rewrite kvm__init
@ 2012-02-09  5:40 Yang Bai
  2012-02-09 13:01 ` Pekka Enberg
  0 siblings, 1 reply; 8+ messages in thread
From: Yang Bai @ 2012-02-09  5:40 UTC (permalink / raw)
  To: penberg; +Cc: kvm, Yang Bai

Since the different issues have been handled in the
internal of kvm__init, it can only return NULL if error
happened.

Signed-off-by: Yang Bai <hamo.by@gmail.com>
---
 tools/kvm/builtin-run.c |    4 ++--
 tools/kvm/kvm.c         |   20 +++++++-------------
 2 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 466169e..b71816f 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -997,8 +997,8 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 	}
 
 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
-	if (IS_ERR(kvm)) {
-		r = PTR_ERR(kvm);
+	if (!kvm) {
+		r = -EFAULT;
 		goto fail;
 	}
 
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 9a0bd67..e3280a8 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -334,17 +334,17 @@ int kvm__max_cpus(struct kvm *kvm)
 
 struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name)
 {
-	struct kvm *kvm;
+	struct kvm *kvm = NULL;
 	int ret;
 
 	if (!kvm__arch_cpu_supports_vm()) {
 		pr_err("Your CPU does not support hardware virtualization");
-		return ERR_PTR(-ENOSYS);
+		return NULL;
 	}
 
 	kvm = kvm__new();
 	if (IS_ERR(kvm))
-		return kvm;
+		return NULL;
 
 	kvm->sys_fd = open(kvm_dev, O_RDWR);
 	if (kvm->sys_fd < 0) {
@@ -358,32 +358,26 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s
 		else
 			pr_err("Could not open %s: ", kvm_dev);
 
-		ret = -errno;
 		goto err_free;
 	}
 
 	ret = ioctl(kvm->sys_fd, KVM_GET_API_VERSION, 0);
 	if (ret != KVM_API_VERSION) {
 		pr_err("KVM_API_VERSION ioctl");
-		ret = -errno;
 		goto err_sys_fd;
 	}
 
 	kvm->vm_fd = ioctl(kvm->sys_fd, KVM_CREATE_VM, 0);
-	if (kvm->vm_fd < 0) {
-		ret = kvm->vm_fd;
+	if (kvm->vm_fd < 0)
 		goto err_sys_fd;
-	}
 
 	kvm->name = strdup(name);
-	if (!kvm->name) {
-		ret = -ENOMEM;
+	if (!kvm->name)
 		goto err;
-	}
 
 	if (kvm__check_extensions(kvm)) {
 		pr_err("A required KVM extention is not supported by OS");
-		ret = -ENOSYS;
+		goto err;
 	}
 
 	kvm__arch_init(kvm, hugetlbfs_path, ram_size);
@@ -400,7 +394,7 @@ err_sys_fd:
 err_free:
 	free(kvm);
 
-	return ERR_PTR(ret);
+	return NULL;
 }
 
 /* RFC 1952 */
-- 
1.7.8.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-02-10  5:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-09  5:40 [PATCH] kvm tool: rewrite kvm__init Yang Bai
2012-02-09 13:01 ` Pekka Enberg
2012-02-09 13:07   ` Cyrill Gorcunov
2012-02-10  2:34     ` Yang Bai
2012-02-10  4:53       ` Sasha Levin
2012-02-10  3:03         ` Yang Bai
2012-02-10  4:17           ` Sasha Levin
2012-02-10  5:04             ` Yang Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).