From patchwork Fri Jun 19 17:24:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 486850 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 A9E0D14018C for ; Sat, 20 Jun 2015 03:25:30 +1000 (AEST) Received: from localhost ([::1]:59340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z602i-0002dK-J1 for incoming@patchwork.ozlabs.org; Fri, 19 Jun 2015 13:25:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z602B-0001Z6-MF for qemu-devel@nongnu.org; Fri, 19 Jun 2015 13:24:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z6027-0000de-Ay for qemu-devel@nongnu.org; Fri, 19 Jun 2015 13:24:55 -0400 Received: from cantor2.suse.de ([195.135.220.15]:59005 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z6027-0000cW-0c for qemu-devel@nongnu.org; Fri, 19 Jun 2015 13:24:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 837C1ADE5; Fri, 19 Jun 2015 17:24:50 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Fri, 19 Jun 2015 19:24:46 +0200 Message-Id: <1434734687-5578-14-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1434734687-5578-1-git-send-email-afaerber@suse.de> References: <1434734687-5578-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Cc: Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PULL v3 13/14] qdev: Deprecated qdev_init() is finally unused, drop 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 From: Markus Armbruster qdev_init() is a wrapper around setting property "realized" to true, plus error handling that passes errors to qerror_report_err(). qerror_report_err() is a transitional interface to help with converting existing monitor commands to QMP. It should not be used elsewhere. All code has been modernized to avoid qdev_init() and its inappropriate error handling. We can finally drop it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Andreas Färber --- hw/core/qdev.c | 47 ++++++++++++++++------------------------------- include/hw/qdev-core.h | 3 +-- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index d10fa5f..a6353c1 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -126,9 +126,9 @@ void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp) qbus_set_hotplug_handler_internal(bus, OBJECT(bus), errp); } -/* Create a new device. This only initializes the device state structure - and allows properties to be set. qdev_init should be called to - initialize the actual device emulation. */ +/* Create a new device. This only initializes the device state + structure and allows properties to be set. The device still needs + to be realized. See qdev-core.h. */ DeviceState *qdev_create(BusState *bus, const char *name) { DeviceState *dev; @@ -168,27 +168,6 @@ DeviceState *qdev_try_create(BusState *bus, const char *type) return dev; } -/* Initialize a device. Device properties should be set before calling - this function. IRQs and MMIO regions should be connected/mapped after - calling this function. - On failure, destroy the device and return negative value. - Return 0 on success. */ -int qdev_init(DeviceState *dev) -{ - Error *local_err = NULL; - - assert(!dev->realized); - - object_property_set_bool(OBJECT(dev), true, "realized", &local_err); - if (local_err != NULL) { - qerror_report_err(local_err); - error_free(local_err); - object_unparent(OBJECT(dev)); - return -1; - } - return 0; -} - static QTAILQ_HEAD(device_listeners, DeviceListener) device_listeners = QTAILQ_HEAD_INITIALIZER(device_listeners); @@ -364,13 +343,19 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, object_unparent(OBJECT(dev)); } -/* Like qdev_init(), but terminate program via error_report() instead of - returning an error value. This is okay during machine creation. - Don't use for hotplug, because there callers need to recover from - failure. Exception: if you know the device's init() callback can't - fail, then qdev_init_nofail() can't fail either, and is therefore - usable even then. But relying on the device implementation that - way is somewhat unclean, and best avoided. */ +/* + * Realize @dev. + * Device properties should be set before calling this function. IRQs + * and MMIO regions should be connected/mapped after calling this + * function. + * On failure, report an error with error_report() and terminate the + * program. This is okay during machine creation. Don't use for + * hotplug, because there callers need to recover from failure. + * Exception: if you know the device's init() callback can't fail, + * then qdev_init_nofail() can't fail either, and is therefore usable + * even then. But relying on the device implementation that way is + * somewhat unclean, and best avoided. + */ void qdev_init_nofail(DeviceState *dev) { Error *err = NULL; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index ad9eb89..64154a9 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -66,7 +66,7 @@ struct VMStateDescription; * After successful realization, setting static properties will fail. * * As an interim step, the #DeviceState:realized property is set by deprecated - * functions qdev_init() and qdev_init_nofail(). + * function qdev_init_nofail(). * In the future, devices will propagate this state change to their children * and along busses they expose. * The point in time will be deferred to machine creation, so that values @@ -262,7 +262,6 @@ typedef struct GlobalProperty { DeviceState *qdev_create(BusState *bus, const char *name); DeviceState *qdev_try_create(BusState *bus, const char *name); -int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT; void qdev_init_nofail(DeviceState *dev); void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version);