From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC7I7-00019n-IP for qemu-devel@nongnu.org; Mon, 06 Jul 2015 10:22:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZC7I5-0000Kc-MV for qemu-devel@nongnu.org; Mon, 06 Jul 2015 10:22:39 -0400 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:33148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC7I5-0000KV-ER for qemu-devel@nongnu.org; Mon, 06 Jul 2015 10:22:37 -0400 Received: by wiwl6 with SMTP id l6so286406631wiw.0 for ; Mon, 06 Jul 2015 07:22:36 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-94-39-132-37.clienti.tiscali.it. [94.39.132.37]) by mx.google.com with ESMTPSA id fq7sm47514674wic.5.2015.07.06.07.22.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 07:22:36 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 6 Jul 2015 16:22:17 +0200 Message-Id: <1436192541-65335-10-git-send-email-pbonzini@redhat.com> In-Reply-To: <1436192541-65335-1-git-send-email-pbonzini@redhat.com> References: <1436192541-65335-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 09/13] kvm-all: kvm_irqchip_create is not expected to fail List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org KVM_CREATE_IRQCHIP should never fail, and so should its userspace wrapper kvm_irqchip_create. The function does not do anything if the irqchip capability is not available, as is the case for PPC. With this patch, kvm_arch_init can allocate memory and it will not be leaked. Signed-off-by: Paolo Bonzini --- kvm-all.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 5f75ac4..42e7615 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1342,27 +1342,31 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq) false); } -static int kvm_irqchip_create(MachineState *machine, KVMState *s) +static void kvm_irqchip_create(MachineState *machine, KVMState *s) { int ret; - if (!machine_kernel_irqchip_allowed(machine) || - (!kvm_check_extension(s, KVM_CAP_IRQCHIP) && - (kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0) < 0))) { - return 0; + if (kvm_check_extension(s, KVM_CAP_IRQCHIP)) { + ; + } else if (kvm_check_extension(s, KVM_CAP_S390_IRQCHIP)) { + ret = kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0); + if (ret < 0) { + fprintf(stderr, "Enable kernel irqchip failed: %s\n", strerror(-ret)); + exit(1); + } + } else { + return; } /* First probe and see if there's a arch-specific hook to create the * in-kernel irqchip for us */ ret = kvm_arch_irqchip_create(s); - if (ret < 0) { - return ret; - } else if (ret == 0) { + if (ret == 0) { ret = kvm_vm_ioctl(s, KVM_CREATE_IRQCHIP); - if (ret < 0) { - fprintf(stderr, "Create kernel irqchip failed\n"); - return ret; - } + } + if (ret < 0) { + fprintf(stderr, "Create kernel irqchip failed: %s\n", strerror(-ret)); + exit(1); } kvm_kernel_irqchip = true; @@ -1373,8 +1377,6 @@ static int kvm_irqchip_create(MachineState *machine, KVMState *s) kvm_halt_in_kernel_allowed = true; kvm_init_irq_routing(s); - - return 0; } /* Find number of supported CPUs using the recommended @@ -1591,9 +1593,8 @@ static int kvm_init(MachineState *ms) goto err; } - ret = kvm_irqchip_create(ms, s); - if (ret < 0) { - goto err; + if (machine_kernel_irqchip_allowed(ms)) { + kvm_irqchip_create(ms, s); } kvm_state = s; -- 1.8.3.1