From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhCmq-0004wN-48 for qemu-devel@nongnu.org; Wed, 30 Sep 2015 04:30:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhCmn-00072j-Dp for qemu-devel@nongnu.org; Wed, 30 Sep 2015 04:30:52 -0400 References: <1443530263-32340-1-git-send-email-pbonzini@redhat.com> <1443530263-32340-3-git-send-email-pbonzini@redhat.com> From: Thomas Huth Message-ID: <560B9DB4.8080707@redhat.com> Date: Wed, 30 Sep 2015 10:30:44 +0200 MIME-Version: 1.0 In-Reply-To: <1443530263-32340-3-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/3] hw: do not pass NULL to memory_region_init from instance_init List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, mark.cave-ayland@ilande.co.uk, agraf@suse.de, armbru@redhat.com, blauwirbel@gmail.com, qemu-ppc@nongnu.org On 29/09/15 14:37, Paolo Bonzini wrote: > This causes the region to outlive the object, because it attaches the > region to /machine. This is not nice for the "realize" method, but > much worse for "instance_init" because it can cause dangling pointers > after a simple object_new/object_unref pair. > > Reported-by: Markus Armbruster > Signed-off-by: Paolo Bonzini ... > diff --git a/hw/display/tcx.c b/hw/display/tcx.c > index 4635800..bf119bc 100644 > --- a/hw/display/tcx.c > +++ b/hw/display/tcx.c > @@ -944,7 +944,7 @@ static void tcx_initfn(Object *obj) > SysBusDevice *sbd = SYS_BUS_DEVICE(obj); > TCXState *s = TCX(obj); > > - memory_region_init_ram(&s->rom, NULL, "tcx.prom", FCODE_MAX_ROM_SIZE, > + memory_region_init_ram(&s->rom, OBJECT(s), "tcx.prom", FCODE_MAX_ROM_SIZE, > &error_fatal); Why "OBJECT(s)" and not simply "obj" ? Thomas