Re: [PATCH] kvm tools: Fix segfault when failing to initialize KVM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 01, 2012 at 09:05:34AM +0200, Pekka Enberg wrote:
> On Tue, 31 Jan 2012, Sasha Levin wrote:
> >Might happen when hardware virtualization is not supported.
> >
> >Reported-by: Ingo Molnar <mingo@xxxxxxx>
> >Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
> >---
> >tools/kvm/builtin-run.c |    4 ++++
> >1 files changed, 4 insertions(+), 0 deletions(-)
> >
> >diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> >index 6ded1d2..a67faf8 100644
> >--- a/tools/kvm/builtin-run.c
> >+++ b/tools/kvm/builtin-run.c
> >@@ -997,6 +997,10 @@ static int kvm_cmd_run_init(int argc, const char **argv)
> >	}
> >
> >	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> >+	if (IS_ERR_OR_NULL(kvm)) {
> >+		r = PTR_ERR(kvm);
> 
> How is this going to work when 'kvm' is NULL? It'd be best if
> kvm_init() never returned NULL on error.
> 
> >+		goto fail;
> >+	}
> >
> >	kvm->single_step = single_step;
> >

I suspect we need something like
---
 tools/kvm/builtin-run.c |    5 +++++
 tools/kvm/kvm.c         |    2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6.git/tools/kvm/builtin-run.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/builtin-run.c
+++ linux-2.6.git/tools/kvm/builtin-run.c
@@ -997,6 +997,11 @@ static int kvm_cmd_run_init(int argc, co
 	}
 
 	kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
+	if (IS_ERR(kvm)) {
+		r = (int)PTR_ERR(kvm);
+		pr_err("Can't initialize KVM, failed with error %d\n", r);
+		goto fail;
+	}
 
 	kvm->single_step = single_step;
 
Index: linux-2.6.git/tools/kvm/kvm.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/kvm.c
+++ linux-2.6.git/tools/kvm/kvm.c
@@ -340,7 +340,7 @@ struct kvm *kvm__init(const char *kvm_de
 	}
 
 	kvm = kvm__new();
-	if (IS_ERR_OR_NULL(kvm))
+	if (IS_ERR(kvm))
 		return kvm;
 
 	kvm->sys_fd = open(kvm_dev, O_RDWR);
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux