From patchwork Wed May 6 11:31:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 468879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2FC1714027F for ; Wed, 6 May 2015 21:32:17 +1000 (AEST) Received: from localhost ([::1]:44227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpxYl-0006Qn-9z for incoming@patchwork.ozlabs.org; Wed, 06 May 2015 07:32:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpxYW-0006AF-Al for qemu-devel@nongnu.org; Wed, 06 May 2015 07:32:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpxYQ-0005qi-UT for qemu-devel@nongnu.org; Wed, 06 May 2015 07:32:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpxYQ-0005qU-No for qemu-devel@nongnu.org; Wed, 06 May 2015 07:31:54 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t46BVr1h032489 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 6 May 2015 07:31:53 -0400 Received: from nilsson.home.kraxel.org (ovpn-116-97.ams2.redhat.com [10.36.116.97]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t46BVqK4024214; Wed, 6 May 2015 07:31:53 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 124F7821CB; Wed, 6 May 2015 13:31:51 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 6 May 2015 13:31:45 +0200 Message-Id: <1430911905-20188-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Gerd Hoffmann Subject: [Qemu-devel] [PATCH] serial: fix multi-pci card error cleanup. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Put the number of serial ports into a local variable in multi_serial_pci_realize, then increment the port count (pci->ports) as we initialize the serial port cores. Now pci->ports always holds the number of successfully initialized ports and we can use multi_serial_pci_exit to properly cleanup the already initialized bits in case of a init failure. https://bugzilla.redhat.com/show_bug.cgi?id=970551 Signed-off-by: Gerd Hoffmann Reviewed-by: Paolo Bonzini --- hw/char/serial-pci.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index 467c3b4..653064f 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -48,6 +48,8 @@ typedef struct PCIMultiSerialState { uint8_t prog_if; } PCIMultiSerialState; +static void multi_serial_pci_exit(PCIDevice *dev); + static void serial_pci_realize(PCIDevice *dev, Error **errp) { PCISerialState *pci = DO_UPCAST(PCISerialState, dev, dev); @@ -89,32 +91,33 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp) PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev); SerialState *s; Error *err = NULL; - int i; + int i, nr_ports = 0; switch (pc->device_id) { case 0x0003: - pci->ports = 2; + nr_ports = 2; break; case 0x0004: - pci->ports = 4; + nr_ports = 4; break; } - assert(pci->ports > 0); - assert(pci->ports <= PCI_SERIAL_MAX_PORTS); + assert(nr_ports > 0); + assert(nr_ports <= PCI_SERIAL_MAX_PORTS); pci->dev.config[PCI_CLASS_PROG] = pci->prog_if; pci->dev.config[PCI_INTERRUPT_PIN] = 0x01; - memory_region_init(&pci->iobar, OBJECT(pci), "multiserial", 8 * pci->ports); + memory_region_init(&pci->iobar, OBJECT(pci), "multiserial", 8 * nr_ports); pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->iobar); pci->irqs = qemu_allocate_irqs(multi_serial_irq_mux, pci, - pci->ports); + nr_ports); - for (i = 0; i < pci->ports; i++) { + for (i = 0; i < nr_ports; i++) { s = pci->state + i; s->baudbase = 115200; serial_realize_core(s, &err); if (err != NULL) { error_propagate(errp, err); + multi_serial_pci_exit(dev); return; } s->irq = pci->irqs[i]; @@ -122,6 +125,7 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp) memory_region_init_io(&s->io, OBJECT(pci), &serial_io_ops, s, pci->name[i], 8); memory_region_add_subregion(&pci->iobar, 8 * i, &s->io); + pci->ports++; } }