From patchwork Thu Feb 3 20:59:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 81786 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 A8953B70CD for ; Fri, 4 Feb 2011 12:07:43 +1100 (EST) Received: from localhost ([127.0.0.1]:35574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pl6NJ-0001fM-GG for incoming@patchwork.ozlabs.org; Thu, 03 Feb 2011 16:05:57 -0500 Received: from [140.186.70.92] (port=42602 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pl6Ht-0007nl-C4 for qemu-devel@nongnu.org; Thu, 03 Feb 2011 16:00:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pl6HG-0004fH-PB for qemu-devel@nongnu.org; Thu, 03 Feb 2011 15:59:44 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:57552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pl6HG-0004fC-JU for qemu-devel@nongnu.org; Thu, 03 Feb 2011 15:59:42 -0500 Received: by pwj6 with SMTP id 6so404546pwj.4 for ; Thu, 03 Feb 2011 12:59:41 -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=ucWVwH94SzTEtLyUmZ936yI0YtZIgrYGeOQZVT4KBJ3LmZtDV95M63SAe/GPkre4Zo ica5GYgGHW1nxB64lfZacO8SQDH2NEY0kEpoZijLyIK+yfxsa3XPBIImUJ2vBHzeMKye 274AcZYOLGXOlGqjl8zvubh8XNzTWg/t0524c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=xTIhTFsplRXRAN8UIG8BegulmJ2oBpsS1U8NvdxMnz2hFbnXNH9Zify2yY4FfEGkVl 3rX/b9A1rKWImmpPcGdGDxt4kxukynkF5aMRIIS5TMtp+ozdjSh2PowbQRkemKIi5Ch4 P8Gf9Ukod2FFX6gu9AfbPRMz+eje3+ZqpU41E= Received: by 10.142.199.7 with SMTP id w7mr10712152wff.61.1296766781796; Thu, 03 Feb 2011 12:59:41 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.52.1 with HTTP; Thu, 3 Feb 2011 12:59:21 -0800 (PST) From: Blue Swirl Date: Thu, 3 Feb 2011 20:59:21 +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 02/10] 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;