From patchwork Fri Mar 4 07:49:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 8499821 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 331979F659 for ; Fri, 4 Mar 2016 07:52:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 947DF201BB for ; Fri, 4 Mar 2016 07:51:59 +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 195D720166 for ; Fri, 4 Mar 2016 07:51:55 +0000 (UTC) Received: from localhost ([::1]:39337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abkWg-0004cW-HG for patchwork-qemu-devel@patchwork.kernel.org; Fri, 04 Mar 2016 02:51:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abkUg-00018c-Nx for qemu-devel@nongnu.org; Fri, 04 Mar 2016 02:49:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abkUf-0001AF-RA for qemu-devel@nongnu.org; Fri, 04 Mar 2016 02:49:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33466) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abkUf-00019y-LP for qemu-devel@nongnu.org; Fri, 04 Mar 2016 02:49:49 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 443D07EBA2; Fri, 4 Mar 2016 07:49:49 +0000 (UTC) Received: from redhat.com (vpn1-5-36.ams2.redhat.com [10.36.5.36]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u247nk0P016903; Fri, 4 Mar 2016 02:49:47 -0500 Date: Fri, 4 Mar 2016 09:49:46 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1457077710-17678-12-git-send-email-mst@redhat.com> References: <1457077710-17678-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1457077710-17678-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Markus Armbruster , Igor Mammedov Subject: [Qemu-devel] [PULL 11/16] pc-dimm: fix error handling in pc_dimm_check_memdev_is_busy() 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 From: Igor Mammedov If host_memory_backend_get_memory() were to return error and NULL MemoryRegion, pc_dimm_check_memdev_is_busy() would crash dereferencing NULL pointer in memory_region_is_mapped(). But if error is set and non NULL MemoryRegion is returned then error_setg() will fail with "error already set" assertion in error_setv() To avoid above issues use typical error handling pattern for property setters: Error *local_error = NULL; ... error_propagate(errp, local_err); Reported-by: Markus Armbruster Signed-off-by: Igor Mammedov Reviewed-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/pc-dimm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 650f0f8..973bf20 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -364,15 +364,22 @@ static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name, Object *val, Error **errp) { MemoryRegion *mr; + Error *local_err = NULL; - mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp); + mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), &local_err); + if (local_err) { + goto out; + } if (memory_region_is_mapped(mr)) { char *path = object_get_canonical_path_component(val); - error_setg(errp, "can't use already busy memdev: %s", path); + error_setg(&local_err, "can't use already busy memdev: %s", path); g_free(path); } else { - qdev_prop_allow_set_link_before_realize(obj, name, val, errp); + qdev_prop_allow_set_link_before_realize(obj, name, val, &local_err); } + +out: + error_propagate(errp, local_err); } static void pc_dimm_init(Object *obj)