From patchwork Thu Apr 19 21:27:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10351609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BEBF0602B7 for ; Thu, 19 Apr 2018 21:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADF1D28503 for ; Thu, 19 Apr 2018 21:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A24892856B; Thu, 19 Apr 2018 21:34:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0069328503 for ; Thu, 19 Apr 2018 21:34:50 +0000 (UTC) Received: from localhost ([::1]:50227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9HCb-0007bh-Dy for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Apr 2018 17:34:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9H5q-0002ga-4L for qemu-devel@nongnu.org; Thu, 19 Apr 2018 17:27:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9H5m-0007v5-6h for qemu-devel@nongnu.org; Thu, 19 Apr 2018 17:27:50 -0400 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]:45882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f9H5m-0007ua-2T for qemu-devel@nongnu.org; Thu, 19 Apr 2018 17:27:46 -0400 Received: by mail-qk0-x242.google.com with SMTP id c136so6869984qkb.12 for ; Thu, 19 Apr 2018 14:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SNy0HHx7YmsITmQIo3InF50vraV4SIqPVmjc0lxdjKc=; b=tZWJWu92S+/40Xo/UyTxmAs03mmrXDjc7AITqoFE84xROi2kP16lZqQ3M5lO/ktaWV PiT+2G/T00Qv7s8nfepTS1TV/kZza8MidGFh0BrLhEaHpBlc/aZcDoT0QCQ2i8EGJeHV QcbL80+BuFc7VI6+SRhb+lpYCFUoxs0q5JE/H3eSAh1VMJRQ84Us05v8oUDYHuWW7X9h 0kdnIkWxfUfP338ldYvMNl86EQ2FPrlWVil6c3uqIVoWUVHyxngkg2XMTW9vpJfgKGfx ta1m7xq4z7qo1mK1rT9O9j+HqR1KWAUtK1rwYvkWzU8fZvW/Alr/BYjSeJbDltvuugtN wFxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SNy0HHx7YmsITmQIo3InF50vraV4SIqPVmjc0lxdjKc=; b=ojmvQJPmWQAbL1UVAnLwg7zcbVKOD5JgHrhzJOiqDHw8YxpIU/aGbNEtW5W3vVeUAj S/oLNRbmKzcfUX4A3RYKDJVUlnF3yjGIlGLb1WW/RLdC1iK+0WUCVPfvhCa1xWa8Vu5P YGktJG18SWUpZ9s8V+3Xj9RNKRI0eIhaouxgaBf68sJOBatalw/7q0MA+7z2FlcWPqq+ Xu6m9UeRx2yWRV21J/g1Nwf4vJMzh8GvmTDPmn2obkTIqc2Ll9jbECjdXNwU2s9MquU3 IN1I+zMtZzcueU4oHfMW6PHOQHQUQmSxcPhzu5UEXR/9mgeaj0w2PlTHPp10fAyWDnzA KkUQ== X-Gm-Message-State: ALQs6tBNuIpHmzJDQoYziyUn0EbRCYsyb6+vhXq9ZazRVe6iICr7To86 WmMcrlkNo5+EKoJob9pUIF0= X-Google-Smtp-Source: AB8JxZruZVnvM4oSEiBDNFL6zpdLUVRKblMl2dlwoRBFqr6ln5ApQmRLQTBLhjeZ+ShZaotQkhOuvA== X-Received: by 10.55.71.3 with SMTP id u3mr8095517qka.317.1524173265580; Thu, 19 Apr 2018 14:27:45 -0700 (PDT) Received: from x1.local ([138.117.48.212]) by smtp.gmail.com with ESMTPSA id c137sm3571570qkb.2.2018.04.19.14.27.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Apr 2018 14:27:44 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Eduardo Habkost , Markus Armbruster Date: Thu, 19 Apr 2018 18:27:26 -0300 Message-Id: <20180419212727.26095-4-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180419212727.26095-1-f4bug@amsat.org> References: <20180419212727.26095-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::242 Subject: [Qemu-devel] [PATCH v3 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 , Paolo Bonzini , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The SysBusDevice is the last DeviceClass::init user. 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 Finally, remove the DeviceClass::init, there are no more users. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/qdev-core.h | 2 -- hw/core/qdev.c | 14 -------------- hw/core/sysbus.c | 15 ++++++++++----- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9453588160..6f60748043 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -29,7 +29,6 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; -typedef int (*qdev_initfn)(DeviceState *dev); typedef int (*qdev_event)(DeviceState *dev); typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); @@ -124,7 +123,6 @@ typedef struct DeviceClass { const struct VMStateDescription *vmsd; /* Private to qdev / bus. */ - qdev_initfn init; /* TODO remove, once users are converted to realize */ qdev_event exit; /* TODO remove, once users are converted to unrealize */ const char *bus_type; } DeviceClass; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f6f92473b8..4153b733c8 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -208,19 +208,6 @@ void device_listener_unregister(DeviceListener *listener) QTAILQ_REMOVE(&device_listeners, listener, link); } -static void device_realize(DeviceState *dev, Error **errp) -{ - DeviceClass *dc = DEVICE_GET_CLASS(dev); - - if (dc->init) { - int rc = dc->init(dev); - if (rc < 0) { - error_setg(errp, "Device initialization failed."); - return; - } - } -} - static void device_unrealize(DeviceState *dev, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(dev); @@ -1065,7 +1052,6 @@ static void device_class_init(ObjectClass *class, void *data) DeviceClass *dc = DEVICE_CLASS(class); class->unparent = device_unparent; - dc->realize = device_realize; dc->unrealize = device_unrealize; /* by default all devices were considered as hotpluggable, diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 5d0887f499..11f6d14b84 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,19 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size) } } -static int sysbus_device_init(DeviceState *dev) +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; + /* TODO remove, once users are converted to realize */ + if (sbc->init) { + int rc = sbc->init(sd); + if (rc < 0) { + error_setg(errp, "Device initialization failed."); + return; + } } - return sbc->init(sd); } DeviceState *sysbus_create_varargs(const char *name, @@ -324,7 +329,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,