From patchwork Fri Jun 16 12:04:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Cave-Ayland X-Patchwork-Id: 9791281 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 402EF60325 for ; Fri, 16 Jun 2017 12:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23A0A27F10 for ; Fri, 16 Jun 2017 12:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1894328647; Fri, 16 Jun 2017 12:05:58 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 B6C8227F10 for ; Fri, 16 Jun 2017 12:05:57 +0000 (UTC) Received: from localhost ([::1]:58584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLq0j-0001Yd-0n for patchwork-qemu-devel@patchwork.kernel.org; Fri, 16 Jun 2017 08:05:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLpzI-0001WO-4n for qemu-devel@nongnu.org; Fri, 16 Jun 2017 08:04:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLpzH-0007kI-6Z for qemu-devel@nongnu.org; Fri, 16 Jun 2017 08:04:28 -0400 Received: from chuckie.co.uk ([82.165.15.123]:52928 helo=s16892447.onlinehome-server.info) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLpzH-0007gn-07 for qemu-devel@nongnu.org; Fri, 16 Jun 2017 08:04:27 -0400 Received: from host109-151-5-7.range109-151.btcentralplus.com ([109.151.5.7] helo=kentang.home) by s16892447.onlinehome-server.info with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1dLpzE-0003XB-5x; Fri, 16 Jun 2017 13:04:25 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, lersek@redhat.com, somlo@cmu.edu, ehabkost@redhat.com, mst@redhat.com, pbonzini@redhat.com, rjones@redhat.com, peter.maydell@linaro.org Date: Fri, 16 Jun 2017 13:04:09 +0100 Message-Id: <1497614651-1017-4-git-send-email-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1497614651-1017-1-git-send-email-mark.cave-ayland@ilande.co.uk> References: <1497614651-1017-1-git-send-email-mark.cave-ayland@ilande.co.uk> X-SA-Exim-Connect-IP: 109.151.5.7 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk X-SA-Exim-Version: 4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000) X-SA-Exim-Scanned: Yes (on s16892447.onlinehome-server.info) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 82.165.15.123 Subject: [Qemu-devel] [PATCHv3 3/5] fw_cfg: move assert() and linking of fw_cfg device to the machine into instance_init() 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In preparation for calling fw_cfg_init1() during realize rather than during init, move the assert() checking for existing fw_cfg devices and the linking of the device to the machine with object_property_add_child() to a new fw_cfg instance_init() function. This guarantees that we will still assert() correctly if more than one fw_cfg device is instantiated by accident. Signed-off-by: Mark Cave-Ayland --- hw/nvram/fw_cfg.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index e217239..39fcc04 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -916,10 +916,6 @@ static void fw_cfg_init1(DeviceState *dev) MachineState *machine = MACHINE(qdev_get_machine()); uint32_t version = FW_CFG_VERSION; - assert(!object_resolve_path(FW_CFG_PATH, NULL)); - - object_property_add_child(OBJECT(machine), FW_CFG_NAME, OBJECT(s), NULL); - qdev_init_nofail(dev); fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4); @@ -1021,6 +1017,15 @@ FWCfgState *fw_cfg_find(void) return FW_CFG(object_resolve_path(FW_CFG_PATH, NULL)); } +static void fw_cfg_init(Object *obj) +{ + MachineState *machine = MACHINE(qdev_get_machine()); + + assert(!object_resolve_path(FW_CFG_PATH, NULL)); + + object_property_add_child(OBJECT(machine), FW_CFG_NAME, obj, NULL); +} + static void fw_cfg_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -1034,6 +1039,7 @@ static const TypeInfo fw_cfg_info = { .parent = TYPE_SYS_BUS_DEVICE, .abstract = true, .instance_size = sizeof(FWCfgState), + .instance_init = fw_cfg_init, .class_init = fw_cfg_class_init, };