From patchwork Wed Feb 2 18:27:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 81523 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 ozlabs.org (Postfix) with ESMTPS id 8D7FEB70EA for ; Thu, 3 Feb 2011 06:35:14 +1100 (EST) Received: from localhost ([127.0.0.1]:44569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkiTv-0003jh-Sq for incoming@patchwork.ozlabs.org; Wed, 02 Feb 2011 14:35:11 -0500 Received: from [140.186.70.92] (port=47572 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkhQz-00047S-FX for qemu-devel@nongnu.org; Wed, 02 Feb 2011 13:28:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkhQx-0003xq-QK for qemu-devel@nongnu.org; Wed, 02 Feb 2011 13:28:05 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:54471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkhQx-0003xR-Lg for qemu-devel@nongnu.org; Wed, 02 Feb 2011 13:28:03 -0500 Received: by pwj6 with SMTP id 6so195354pwj.4 for ; Wed, 02 Feb 2011 10:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=SdPnaC7ATmC6dsk+vFGPS5FOEgUVljBW1iWqkI7iSNo=; b=vGSQ1RIjKZGzTXCad5Ghxe/fCJA8Ff5Q52e9bscBIrOHXOHaOmSn8dueLweHZWGq// fSn0xVauRG0pSAL/791HvcVL+YAPRAH4IgXcmZGsm37qnztwxEHushTCq6JGoFEk1E9d fBud/06J/4UNc7lQ1iFzbWHvYhSaYmfz63Xnw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=MK5I6EyquPCvjGGU0IS4iNshumbI1YXfPmAIIm4uzwD/vZbmljb+/Ltodo3+DjIY00 4P/yEMU0NBnq/48gZQP/R9ORMSo5If/P6K+q1OlMJOORV4IW7Mxn5Bp5iy48bzp1pc1w P+IzUUp8X0TikrWXY0mC04AjSZETKFJvsWDuk= Received: by 10.142.136.21 with SMTP id j21mr681565wfd.173.1296671283035; Wed, 02 Feb 2011 10:28:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.241.1 with HTTP; Wed, 2 Feb 2011 10:27:42 -0800 (PST) From: Blue Swirl Date: Wed, 2 Feb 2011 18:27:42 +0000 Message-ID: To: qemu-devel X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 2/4] qdev: add creation function that may fail 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 Signed-off-by: Blue Swirl --- hw/qdev.c | 14 +++++++++++++- hw/qdev.h | 1 + 2 files changed, 14 insertions(+), 1 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index c7fec44..1aa1ea0 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -106,6 +106,18 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) initialize the actual device emulation. */ DeviceState *qdev_create(BusState *bus, const char *name) { + DeviceState *dev; + + dev = qdev_try_create(bus, name); + if (!dev) { + hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name); + } + + return dev; +} + +DeviceState *qdev_try_create(BusState *bus, const char *name) +{ DeviceInfo *info; if (!bus) { @@ -114,7 +126,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) info = qdev_find_info(bus->info, name); if (!info) { - hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name); + return NULL; } return qdev_create_from_info(bus, info); diff --git a/hw/qdev.h b/hw/qdev.h index 9808f85..8a13ec9 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -122,6 +122,7 @@ typedef struct GlobalProperty { /*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create(BusState *bus, const char *name); +DeviceState *qdev_try_create(BusState *bus, const char *name); int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts); int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;