Received: from eggs.gnu.org ([2001:4830:134:3::10]:57876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagmy-0007y6-6U for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:40:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aagmt-00060x-PN for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:40:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagmt-00060s-Iy for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:40:15 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 0FA01634C for ; Tue, 1 Mar 2016 09:40:15 +0000 (UTC) Date: Tue, 1 Mar 2016 10:40:12 +0100 From: Igor Mammedov Message-ID: <20160301104012.5e6973b4@nial.brq.redhat.com> In-Reply-To: <87d1rftlhw.fsf@blackfin.pond.sub.org> References: <1456750898-152238-1-git-send-email-imammedo@redhat.com> <87d1rftlhw.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] pc-dimm: fix error handling in pc_dimm_check_memdev_is_busy() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, mst@redhat.com On Mon, 29 Feb 2016 19:33:15 +0100 Markus Armbruster wrote: > Igor Mammedov writes: > > > if host_memory_backend_get_memory() were to return error and > > Start sentences with a capital letter, please. > > > NULL MemoryRegion, pc_dimm_check_memdev_is_busy() would crash > > dereferrencing null pointer in memory_region_is_mapped() > > dereferencing > > > > > Also pc_dimm_check_memdev_is_busy():error_setg() would assert > > if caller passes NULL errp, but assert shouldn't happen as > > the check is typically performed during hotplug. > > Huh? Yep, this paragraph is wrong, I'll drop it. > > > > > 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 > > The latent bug I reported was actually that if > host_memory_backend_get_memory() sets an error and we then reach > error_setg(), we fail the "error already set" assertion in error_setv() > unless errp is null. > > > Signed-off-by: Igor Mammedov > > --- > > 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) > > I'd error_propagate() + return instead of goto. But your version isn't > wrong, so: > > Reviewed-by: Markus Armbruster > > Preferably with an improved commit message, of course :) Thanks, I'll respin v2 with fixed commit message.