From patchwork Tue Mar 1 06:18: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: 8462171 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E0CAF9F38C for ; Tue, 1 Mar 2016 06:20:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 446B0202C8 for ; Tue, 1 Mar 2016 06:20:35 +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 87589202AE for ; Tue, 1 Mar 2016 06:20:34 +0000 (UTC) Received: from localhost ([::1]:41166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aadfd-0007lj-TK for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 01:20:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaddu-0004l0-QB for qemu-devel@nongnu.org; Tue, 01 Mar 2016 01:18:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaddr-0005nK-Ka for qemu-devel@nongnu.org; Tue, 01 Mar 2016 01:18:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaddr-0005nG-Ep for qemu-devel@nongnu.org; Tue, 01 Mar 2016 01:18:43 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 2B30B821C3; Tue, 1 Mar 2016 06:18:43 +0000 (UTC) Received: from fam-t430.redhat.com (vpn1-5-42.pek2.redhat.com [10.72.5.42]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u216IPXZ031427; Tue, 1 Mar 2016 01:18:39 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 1 Mar 2016 14:18:19 +0800 Message-Id: <1456813104-25902-3-git-send-email-famz@redhat.com> In-Reply-To: <1456813104-25902-1-git-send-email-famz@redhat.com> References: <1456813104-25902-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , arei.gonglei@huawei.com, peterx@redhat.com Subject: [Qemu-devel] [PATCH v2 2/7] 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. Reviewed-by: Gonglei Signed-off-by: Fam Zheng --- 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; }