From patchwork Mon May 28 14:45:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 921578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 40vfpH0TyZz9s0y for ; Tue, 29 May 2018 00:47:19 +1000 (AEST) Received: from localhost ([::1]:56596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJQa-0000pd-Rf for incoming@patchwork.ozlabs.org; Mon, 28 May 2018 10:47:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJOf-0008O9-1L for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNJOZ-0005d9-V6 for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59660 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNJOZ-0005c1-Ql for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D592401EF04; Mon, 28 May 2018 14:45:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7A191C595; Mon, 28 May 2018 14:45:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id ACEB8113866B; Mon, 28 May 2018 16:45:09 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 28 May 2018 16:45:08 +0200 Message-Id: <20180528144509.15812-4-armbru@redhat.com> In-Reply-To: <20180528144509.15812-1-armbru@redhat.com> References: <20180528144509.15812-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 28 May 2018 14:45:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 28 May 2018 14:45:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 3/4] qdev: Simplify the SysBusDeviceClass::init path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, thuth@redhat.com, pbonzini@redhat.com, f4bug@amsat.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Instead of using SysBusDeviceClass::realize -> DeviceClass::realize -> DeviceClass::init -> sysbus_device_init -> SysBusDeviceClass::init Simplify the path by directly calling SysBusDeviceClass::init in SysBusDeviceClass::realize: SysBusDeviceClass::realize -> SysBusDeviceClass::init Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20180419212727.26095-4-f4bug@amsat.org> Reviewed-by: Markus Armbruster [Removal of DeviceClass::init() moved into next patch, sysbus_realize() tweaked for clarity] Signed-off-by: Markus Armbruster --- hw/core/sysbus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 5d0887f499..ecfb0cfc0e 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/sysbus.h" #include "monitor/monitor.h" #include "exec/address-spaces.h" @@ -200,15 +201,18 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size) } } -static int sysbus_device_init(DeviceState *dev) +/* TODO remove once all sysbus devices have been converted to realize */ +static void sysbus_realize(DeviceState *dev, Error **errp) { SysBusDevice *sd = SYS_BUS_DEVICE(dev); SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd); if (!sbc->init) { - return 0; + return; + } + if (sbc->init(sd) < 0) { + error_setg(errp, "Device initialization failed"); } - return sbc->init(sd); } DeviceState *sysbus_create_varargs(const char *name, @@ -324,7 +328,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev) static void sysbus_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); - k->init = sysbus_device_init; + k->realize = sysbus_realize; k->bus_type = TYPE_SYSTEM_BUS; /* * device_add plugs devices into a suitable bus. For "real" buses,