From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvJGQ-0003Nr-E7 for qemu-devel@nongnu.org; Tue, 06 Oct 2009 19:16:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvJGK-0003LL-Vh for qemu-devel@nongnu.org; Tue, 06 Oct 2009 19:16:12 -0400 Received: from [199.232.76.173] (port=52561 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvJGK-0003Ky-8d for qemu-devel@nongnu.org; Tue, 06 Oct 2009 19:16:08 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:50057) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvJGJ-0005IM-P7 for qemu-devel@nongnu.org; Tue, 06 Oct 2009 19:16:08 -0400 Received: from pike.pond.sub.org (pD9E3BD77.dip.t-dialin.net [217.227.189.119]) by oxygen.pond.sub.org (Postfix) with ESMTPA id A6395276D3F for ; Wed, 7 Oct 2009 01:16:06 +0200 (CEST) From: Markus Armbruster Date: Wed, 7 Oct 2009 01:15:56 +0200 Message-Id: <7b69c8f6826f0e059347a0cbf46bd8b99ddfbb18.1254867902.git.armbru@redhat.com> In-Reply-To: References: Subject: [Qemu-devel] [PATCH 2/7] Make qdev_init() destroy the device on failure List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@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 | 9 ++++++--- 2 files changed, 6 insertions(+), 4 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 253e255..8a62001 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -216,7 +216,6 @@ DeviceState *qdev_device_add(QemuOpts *opts) } if (qdev_init(qdev) != 0) { qemu_error("Error initializing device %s\n", driver); - qdev_free(qdev); return NULL; } qdev->opts = opts; @@ -232,15 +231,19 @@ static void qdev_reset(void *opaque) /* 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; assert(dev->state == DEV_STATE_CREATED); rc = dev->info->init(dev, dev->info); - if (rc < 0) + if (rc < 0) { + qdev_free(dev); return rc; + } qemu_register_reset(qdev_reset, dev); if (dev->info->vmsd) vmstate_register(-1, dev->info->vmsd, dev); -- 1.6.2.5