From nobody Tue Feb 10 22:18:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516622953532124.80876248256868; Mon, 22 Jan 2018 04:09:13 -0800 (PST) Received: from localhost ([::1]:38122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edauU-0007ia-L1 for importer@patchew.org; Mon, 22 Jan 2018 07:09:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edapk-00044x-QH for qemu-devel@nongnu.org; Mon, 22 Jan 2018 07:04:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edapj-0000Jw-LU for qemu-devel@nongnu.org; Mon, 22 Jan 2018 07:04:16 -0500 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:40210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edapj-0000Jn-Go for qemu-devel@nongnu.org; Mon, 22 Jan 2018 07:04:15 -0500 Received: by mail-qt0-x241.google.com with SMTP id s39so20044789qth.7 for ; Mon, 22 Jan 2018 04:04:15 -0800 (PST) Received: from x1.local ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id 92sm11295356qky.72.2018.01.22.04.04.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 04:04:14 -0800 (PST) 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=YVY+KRXx/zqkeeY62jHtBGTo4R5Ilz7voW1TvxymbpI=; b=hHVd0roN5cOQMULVQkrzTw9pDUkjraCCQ+zzxE3w6ArpWxKPfHuyLHhBGhXaov6fHN ScXJFK5y1pN9QkibHkPO/2as8LThiENuprOFyBA81Gpse9wJXzg3BhObramA/6pXjYw3 Q5H02SiKRPlZeLGgMqnCgZDkFf1XSN8kckoX5np8/oM3CM/B0QXUXW1bHTSLsZsz4PNz PYBvihOwoctNnjBKm9qQ0bzya8DA/jMjeLgT+KBfmWaeB1E+w3qLN4ns/2jLFHpjYGZd R1sX/vyF8yn6M3qzB7PnF7OnnCP0Sy7U18wSd8maTcUJezZo+V/a2ggegmbMGc20T03q CtFA== 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=YVY+KRXx/zqkeeY62jHtBGTo4R5Ilz7voW1TvxymbpI=; b=SMUXWrcwc+a4fhXccEq70SaJ6Obw/Ic4RemMqcUPzVN8H08fMIB88165D4n3au5X+8 WxmiFocwZbl7A+PwQComxd7z54iE+usRFIKp5/q7iOoGORsaqwNb2VoQPmMKnwAmLZtR MVvDvAUU1n3I7VZkSx6Q00WmMdM96Nsz1IGnqgKOJg4SVmcTWntZjohwqTUm/lvOamSp VxVNmAZpSnq6rBt2lkW+E1MYgmOADoxNKN99GhtHgfTuQXAx0aTCC0Q1kfFlzRtPFgGf h+e7NS2ZLkkUO3lw4+Aopn0a274VQPIrxR6vqteStWFjpq24UiIMlbvEziZEMX5Ir0hf +P2g== X-Gm-Message-State: AKwxyteS8FOki/uizvgtiKlcWt3RG6H9sx1EIyftm+9t07wQwxex/xOR fjtVA91HqM+zPUQSQMxb44YgwjUJ X-Google-Smtp-Source: AH8x226/R5ZMrfkxhDGvgddaaTy7WV8wioQ7vlp3yqn5eCASYsxWVTlhZvRVB+erML0QT7cFwL/uYA== X-Received: by 10.200.62.129 with SMTP id y1mr9614202qtf.21.1516622655005; Mon, 22 Jan 2018 04:04:15 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Eduardo Habkost , Paolo Bonzini Date: Mon, 22 Jan 2018 09:03:49 -0300 Message-Id: <20180122120351.22369-6-f4bug@amsat.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180122120351.22369-1-f4bug@amsat.org> References: <20180122120351.22369-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v2 5/7] 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 , Markus Armbruster , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9 --- 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 51473eee7b..fd386b5d49 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -30,7 +30,6 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; =20 -typedef int (*qdev_initfn)(DeviceState *dev); typedef int (*qdev_event)(DeviceState *dev); typedef void (*qdev_resetfn)(DeviceState *dev); typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); @@ -125,7 +124,6 @@ typedef struct DeviceClass { const struct VMStateDescription *vmsd; =20 /* 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 f739753e3a..1a985a511e 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -219,19 +219,6 @@ void device_listener_unregister(DeviceListener *listen= er) QTAILQ_REMOVE(&device_listeners, listener, link); } =20 -static void device_realize(DeviceState *dev, Error **errp) -{ - DeviceClass *dc =3D DEVICE_GET_CLASS(dev); - - if (dc->init) { - int rc =3D dc->init(dev); - if (rc < 0) { - error_setg(errp, "Device initialization failed."); - return; - } - } -} - static void device_unrealize(DeviceState *dev, Error **errp) { DeviceClass *dc =3D DEVICE_GET_CLASS(dev); @@ -1139,7 +1126,6 @@ static void device_class_init(ObjectClass *class, voi= d *data) DeviceClass *dc =3D DEVICE_CLASS(class); =20 class->unparent =3D device_unparent; - dc->realize =3D device_realize; dc->unrealize =3D device_unrealize; =20 /* 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 @@ */ =20 #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) } } =20 -static int sysbus_device_init(DeviceState *dev) +static void sysbus_realize(DeviceState *dev, Error **errp) { SysBusDevice *sd =3D SYS_BUS_DEVICE(dev); SysBusDeviceClass *sbc =3D SYS_BUS_DEVICE_GET_CLASS(sd); =20 - if (!sbc->init) { - return 0; + /* TODO remove, once users are converted to realize */ + if (sbc->init) { + int rc =3D sbc->init(sd); + if (rc < 0) { + error_setg(errp, "Device initialization failed."); + return; + } } - return sbc->init(sd); } =20 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 =3D DEVICE_CLASS(klass); - k->init =3D sysbus_device_init; + k->realize =3D sysbus_realize; k->bus_type =3D TYPE_SYSTEM_BUS; /* * device_add plugs devices into a suitable bus. For "real" buses, --=20 2.15.1