From patchwork Tue Jun 28 13:58:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 641573 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rf6tT6g0Zz9sXy for ; Wed, 29 Jun 2016 00:01:53 +1000 (AEST) Received: from localhost ([::1]:36961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHtaJ-0006kM-Oz for incoming@patchwork.ozlabs.org; Tue, 28 Jun 2016 10:01:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHtWq-0004CJ-DA for qemu-devel@nongnu.org; Tue, 28 Jun 2016 09:58:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHtWo-0008Gi-Hc for qemu-devel@nongnu.org; Tue, 28 Jun 2016 09:58:15 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58004) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHtWm-0008Fu-4P; Tue, 28 Jun 2016 09:58:12 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bHtWj-00063N-N8; Tue, 28 Jun 2016 14:58:09 +0100 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 28 Jun 2016 14:58:07 +0100 Message-Id: <1467122287-24974-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467122287-24974-1-git-send-email-peter.maydell@linaro.org> References: <1467122287-24974-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.7 3/3] memory: Assert that memory_region_init_rom_device() ops aren't NULL 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: , Cc: Paolo Bonzini , Jean-Christophe DUBOIS , patches@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It doesn't make sense to pass a NULL ops argument to memory_region_init_rom_device(), because the effect will be that if the guest tries to write to the memory region then QEMU will segfault. Catch the bug earlier by sanity checking the arguments to this function, and remove the misleading documentation that suggests that passing NULL might be sensible. Signed-off-by: Peter Maydell --- include/exec/memory.h | 5 +---- memory.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 742c52f..0435e79 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -463,12 +463,9 @@ void memory_region_init_rom(MemoryRegion *mr, * memory_region_init_rom_device: Initialize a ROM memory region. Writes are * handled via callbacks. * - * If NULL callbacks pointer is given, then I/O space is not supposed to be - * handled by QEMU itself. Any access via the memory API will cause an abort(). - * * @mr: the #MemoryRegion to be initialized. * @owner: the object that tracks the region's reference count - * @ops: callbacks for write access handling. + * @ops: callbacks for write access handling (must not be NULL). * @name: the name of the region. * @size: size of the region. * @errp: pointer to Error*, to store an error if it happens. diff --git a/memory.c b/memory.c index c18ccc8..de0d4b5 100644 --- a/memory.c +++ b/memory.c @@ -1399,6 +1399,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, uint64_t size, Error **errp) { + assert(ops); memory_region_init(mr, owner, name, size); mr->ops = ops; mr->opaque = opaque;