All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Bai <hamo.by@gmail.com>
To: penberg@kernel.org
Cc: kvm@vger.kernel.org, Yang Bai <hamo.by@gmail.com>
Subject: [PATCH 2/4] kvm tool: unite the error handle in kvm__init
Date: Fri, 10 Feb 2012 17:55:34 +0800	[thread overview]
Message-ID: <1328867736-4394-2-git-send-email-hamo.by@gmail.com> (raw)
In-Reply-To: <1328867736-4394-1-git-send-email-hamo.by@gmail.com>

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>
---
 tools/kvm/kvm.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 8e749ad..192d70e 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);
 }
 
-- 
1.7.8.3


  reply	other threads:[~2012-02-10  9:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  9:55 [PATCH 1/4] kvm tool: Stop init if check_extensions failed Yang Bai
2012-02-10  9:55 ` Yang Bai [this message]
2012-02-10  9:55 ` [PATCH 3/4] kvm tool: if kvm_ipc__start failed, return negative Yang Bai
2012-02-10  9:55 ` [PATCH 4/4] kvm tool: ensure kvm_ipc__register_handler success Yang Bai
2012-02-10 11:38 ` [PATCH 1/4] kvm tool: Stop init if check_extensions failed Pekka Enberg

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=1328867736-4394-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.