From: Will Deacon Subject: [RFC PATCH 07/16] kvm tools: die if init_list__init returns failure Date: Mon, 12 Nov 2012 11:57:21 +0000 Message-ID: <1352721450-11340-8-git-send-email-will.deacon@arm.com> References: <1352721450-11340-1-git-send-email-will.deacon@arm.com> Cc: penberg@kernel.org, marc.zyngier@arm.com, c.dall@virtualopensystems.com, matt.evans@arm.com, peter.maydell@linaro.org, Will Deacon To: kvm@vger.kernel.org Return-path: Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:55163 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752848Ab2KLL5j (ORCPT ); Mon, 12 Nov 2012 06:57:39 -0500 In-Reply-To: <1352721450-11340-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org List-ID: If init_list__init returns failure when initialising kvm tool, we can't rely on our structures being fully initialised, so die rather than try to continue and fail gracefully later on. This prevents a SEGV when kvm is not available on the host: Error: '/dev/kvm' not found. Please make sure your kernel has CONFIG_KVM enabled and that the KVM modules are loaded. Warning: Failed init: kvm__init Segmentation fault Signed-off-by: Will Deacon --- tools/kvm/builtin-run.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index dec2e74..96e68af 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -665,7 +665,8 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv) printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME, kvm->cfg.kernel_filename, kvm->cfg.ram_size / 1024 / 1024, kvm->cfg.nrcpus, kvm->cfg.guest_name); - init_list__init(kvm); + if (init_list__init(kvm) < 0) + die ("Initialisation failed"); return kvm; } -- 1.7.4.1