From patchwork Sat Jun 22 08:50:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 253377 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 0E4B42C040D for ; Sat, 22 Jun 2013 18:58:21 +1000 (EST) Received: from localhost ([::1]:56073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqJeE-0003MZ-Vg for incoming@patchwork.ozlabs.org; Sat, 22 Jun 2013 04:58:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqJY0-00014m-Ez for qemu-devel@nongnu.org; Sat, 22 Jun 2013 04:51:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UqJXx-0003b6-9o for qemu-devel@nongnu.org; Sat, 22 Jun 2013 04:51:52 -0400 Received: from [222.73.24.84] (port=12713 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqJXw-0003ZE-UP for qemu-devel@nongnu.org; Sat, 22 Jun 2013 04:51:49 -0400 X-IronPort-AV: E=Sophos;i="4.87,917,1363104000"; d="scan'208";a="7638491" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 22 Jun 2013 16:48:35 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r5M8pTIm002349; Sat, 22 Jun 2013 16:51:30 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com ([10.167.233.156]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013062216502056-2388916 ; Sat, 22 Jun 2013 16:50:20 +0800 From: Hu Tao To: qemu-devel Date: Sat, 22 Jun 2013 16:50:23 +0800 Message-Id: <001b05e5b5dec4cdab184c95d527c0e1310ec26b.1371804804.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/22 16:50:20, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/22 16:50:21, Serialize complete at 2013/06/22 16:50:21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Kevin Wolf , Peter Crosthwaite , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 11/26] pflash_cfi02: use 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 Cc: Kevin Wolf Cc: Stefan Hajnoczi Signed-off-by: Hu Tao --- hw/block/pflash_cfi02.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 5f25246..45db415 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -586,9 +586,9 @@ 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 = FROM_SYSBUS(typeof(*pfl), dev); + pflash_t *pfl = DO_UPCAST(typeof(*pfl), busdev.qdev, dev); uint32_t chip_len; int ret; @@ -610,14 +610,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); @@ -706,8 +708,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[] = { @@ -730,9 +730,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; }