From: Yang Bai <hamo.by@gmail.com>
To: penberg@kernel.org
Cc: kvm@vger.kernel.org, Yang Bai <hamo.by@gmail.com>
Subject: [PATCH] kvm tool: rewrite kvm__init
Date: Thu, 9 Feb 2012 13:40:16 +0800 [thread overview]
Message-ID: <1328766016-2644-1-git-send-email-hamo.by@gmail.com> (raw)
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
next reply other threads:[~2012-02-09 5:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-09 5:40 Yang Bai [this message]
2012-02-09 13:01 ` [PATCH] kvm tool: rewrite kvm__init 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328766016-2644-1-git-send-email-hamo.by@gmail.com \
--to=hamo.by@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).