From patchwork Fri Sep 11 20:19:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 33492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 48A30B6F20 for ; Sat, 12 Sep 2009 06:30:09 +1000 (EST) Received: from localhost ([127.0.0.1]:48988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MmCkv-0001pz-Ij for incoming@patchwork.ozlabs.org; Fri, 11 Sep 2009 16:30:05 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MmCaj-0003KJ-RJ for qemu-devel@nongnu.org; Fri, 11 Sep 2009 16:19:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MmCaf-0003HT-Uc for qemu-devel@nongnu.org; Fri, 11 Sep 2009 16:19:33 -0400 Received: from [199.232.76.173] (port=34683 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MmCaf-0003HF-Om for qemu-devel@nongnu.org; Fri, 11 Sep 2009 16:19:29 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:41818) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MmCaf-0005ry-3t for qemu-devel@nongnu.org; Fri, 11 Sep 2009 16:19:29 -0400 Received: from pike.pond.sub.org (pD9E39C1E.dip.t-dialin.net [217.227.156.30]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 120CD276D4F for ; Fri, 11 Sep 2009 22:19:27 +0200 (CEST) Received: by pike.pond.sub.org (Postfix, from userid 1000) id A516610099; Fri, 11 Sep 2009 22:19:21 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 11 Sep 2009 22:19:17 +0200 Message-Id: <7ad8d8aa4136b75b1721568aba48edc8b374234b.1252699478.git.armbru@redhat.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: References: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH 2/6] Make qdev_init() destroy the device on failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Before, every caller had to do this. Only two actually did. Signed-off-by: Markus Armbruster --- hw/isa-bus.c | 1 - hw/qdev.c | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/isa-bus.c b/hw/isa-bus.c index 4ecc0f8..fb90be4 100644 --- a/hw/isa-bus.c +++ b/hw/isa-bus.c @@ -127,7 +127,6 @@ ISADevice *isa_create_simple(const char *name) dev = isa_create(name); if (qdev_init(&dev->qdev) != 0) { - qdev_free(&dev->qdev); return NULL; } return dev; diff --git a/hw/qdev.c b/hw/qdev.c index 6451b8a..107acd8 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -202,8 +202,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) qdev_free(qdev); return NULL; } - if (qdev_init(qdev) != 0) { - qdev_free(qdev); + if (qdev_init(qdev) < 0) { return NULL; } return qdev; @@ -211,14 +210,18 @@ DeviceState *qdev_device_add(QemuOpts *opts) /* Initialize a device. Device properties should be set before calling this function. IRQs and MMIO regions should be connected/mapped after - calling this function. */ + calling this function. + On failure, destroy the device and return negative value. + Return 0 on success. */ int qdev_init(DeviceState *dev) { int rc; rc = dev->info->init(dev, dev->info); - if (rc < 0) + if (rc < 0) { + qdev_free(dev); return rc; + } if (dev->info->reset) qemu_register_reset(dev->info->reset, dev); if (dev->info->vmsd)