From patchwork Mon Jul 22 23:46:26 2013 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: 260865 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 835762C009A for ; Tue, 23 Jul 2013 10:01:44 +1000 (EST) Received: from localhost ([::1]:42747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1Q2w-00075l-AB for incoming@patchwork.ozlabs.org; Mon, 22 Jul 2013 20:01:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1Poy-0003RR-61 for qemu-devel@nongnu.org; Mon, 22 Jul 2013 19:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1Por-00046A-G6 for qemu-devel@nongnu.org; Mon, 22 Jul 2013 19:47:16 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45857 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1Por-00045N-3m for qemu-devel@nongnu.org; Mon, 22 Jul 2013 19:47:09 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 90AFBA41E0; Tue, 23 Jul 2013 01:47:08 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Tue, 23 Jul 2013 01:46:26 +0200 Message-Id: <1374536796-13983-46-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1374536796-13983-1-git-send-email-afaerber@suse.de> References: <1374536796-13983-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: Kevin Wolf , Hu Tao , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 45/55] pflash_cfi02: Use QOM realize for pflash_cfi02 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: Hu Tao Signed-off-by: Hu Tao Signed-off-by: Andreas Färber --- hw/block/pflash_cfi02.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index d8381dd..9fc02e3 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -592,7 +592,7 @@ static const MemoryRegionOps pflash_cfi02_ops_le = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int pflash_cfi02_init(SysBusDevice *dev) +static void pflash_cfi02_realize(DeviceState *dev, Error **errp) { pflash_t *pfl = CFI_PFLASH02(dev); uint32_t chip_len; @@ -616,14 +616,16 @@ static int pflash_cfi02_init(SysBusDevice *dev) /* read the initial flash content */ ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9); if (ret < 0) { - g_free(pfl); - return 1; + vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl)); + memory_region_destroy(&pfl->orig_mem); + error_setg(errp, "failed to read the initial flash content"); + return; } } pflash_setup_mappings(pfl); pfl->rom_mode = 1; - sysbus_init_mmio(dev, &pfl->mem); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); if (pfl->bs) { pfl->ro = bdrv_is_read_only(pfl->bs); @@ -712,8 +714,6 @@ static int pflash_cfi02_init(SysBusDevice *dev) pfl->cfi_table[0x3b] = 0x00; pfl->cfi_table[0x3c] = 0x00; - - return 0; } static Property pflash_cfi02_properties[] = { @@ -736,9 +736,8 @@ static Property pflash_cfi02_properties[] = { static void pflash_cfi02_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = pflash_cfi02_init; + dc->realize = pflash_cfi02_realize; dc->props = pflash_cfi02_properties; }