From patchwork Mon Feb 29 02:37:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 8448381 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 863C0C0553 for ; Mon, 29 Feb 2016 02:37:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E70D320266 for ; Mon, 29 Feb 2016 02:37:55 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 3542420265 for ; Mon, 29 Feb 2016 02:37:55 +0000 (UTC) Received: from localhost ([::1]:33576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaDic-0007zN-K8 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 28 Feb 2016 21:37:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaDiO-0007pw-0a for qemu-devel@nongnu.org; Sun, 28 Feb 2016 21:37:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaDiN-0007wx-3v for qemu-devel@nongnu.org; Sun, 28 Feb 2016 21:37:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaDiM-0007wt-Un for qemu-devel@nongnu.org; Sun, 28 Feb 2016 21:37:39 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 962BF8E3CE for ; Mon, 29 Feb 2016 02:37:38 +0000 (UTC) Received: from fam-t430.redhat.com (vpn1-5-71.pek2.redhat.com [10.72.5.71]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1T2bOsj012949; Sun, 28 Feb 2016 21:37:35 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 29 Feb 2016 10:37:19 +0800 Message-Id: <1456713443-16834-3-git-send-email-famz@redhat.com> In-Reply-To: <1456713443-16834-1-git-send-email-famz@redhat.com> References: <1456713443-16834-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini Subject: [Qemu-devel] [PATCH 2/6] memory: Move assignment to ram_block to memory_region_init_* 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't force "const" qualifiers with pointers in QEMU, but it's still good to keep a clean function interface. Assigning to mr->ram_block is in this sense ugly - one initializer mutating its owning object's state. Move it to memory_region_init_*, where mr->ram_addr is assigned. Signed-off-by: Fam Zheng Reviewed-by: Gonglei --- exec.c | 1 - memory.c | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 2b14b79..83e3f7d 100644 --- a/exec.c +++ b/exec.c @@ -1711,7 +1711,6 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, error_propagate(errp, local_err); return NULL; } - mr->ram_block = new_block; return new_block; } diff --git a/memory.c b/memory.c index ae13ba9..fe70075 100644 --- a/memory.c +++ b/memory.c @@ -1233,6 +1233,7 @@ void memory_region_init_ram(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; ram_block = qemu_ram_alloc(size, mr, errp); + mr->ram_block = ram_block; mr->ram_addr = ram_block->offset; mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } @@ -1254,6 +1255,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; ram_block = qemu_ram_alloc_resizeable(size, max_size, resized, mr, errp); + mr->ram_block = ram_block; mr->ram_addr = ram_block->offset; mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } @@ -1274,6 +1276,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp); + mr->ram_block = ram_block; mr->ram_addr = ram_block->offset; mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } @@ -1296,6 +1299,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert(ptr != NULL); ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_fatal); + mr->ram_block = ram_block; mr->ram_addr = ram_block->offset; } @@ -1333,6 +1337,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->rom_device = true; mr->destructor = memory_region_destructor_rom_device; ram_block = qemu_ram_alloc(size, mr, errp); + mr->ram_block = ram_block; mr->ram_addr = ram_block->offset; }