From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm0dq-0007Xr-N1 for qemu-devel@nongnu.org; Wed, 05 Nov 2014 08:29:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xm0dj-0000nr-2b for qemu-devel@nongnu.org; Wed, 05 Nov 2014 08:28:54 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:51758) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm0di-0000n7-OI for qemu-devel@nongnu.org; Wed, 05 Nov 2014 08:28:46 -0500 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NEK00176IRWVZ00@mailout1.samsung.com> for qemu-devel@nongnu.org; Wed, 05 Nov 2014 22:28:44 +0900 (KST) From: SeokYeon Hwang References: <1415182311-13799-1-git-send-email-syeon.hwang@samsung.com> <20141105124609.GA4354@redhat.com> In-reply-to: <20141105124609.GA4354@redhat.com> Date: Wed, 05 Nov 2014 22:28:46 +0900 Message-id: <040e01cff8fc$6d552f60$47ff8e20$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit Content-language: ko Subject: Re: [Qemu-devel] [PATCH] pci: fixed mismatch of error-handling between pci_qdev_init() and qdev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "'Michael S. Tsirkin'" Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com > -----Original Message----- > From: Michael S. Tsirkin [mailto:mst@redhat.com] > Sent: Wednesday, November 05, 2014 9:46 PM > To: SeokYeon Hwang > Cc: qemu-devel@nongnu.org; armbru@redhat.com; pbonzini@redhat.com > Subject: Re: [PATCH] pci: fixed mismatch of error-handling between > pci_qdev_init() and qdev > > On Wed, Nov 05, 2014 at 07:11:51PM +0900, SeokYeon Hwang wrote: > > pci_qdev_init() checks whether return value is 0 or not to figure out > pci device is initialized successfully. Otherwise, device_realize() in > qdev checks that return value is negative value to figure out the device > is realized successfully. > > When pci device returns positive number, pci_qdev_init() thinks that > error is occured and makes the device unregistered. Nevertheless, qdev > thinks that device is realized. > > Finally, crash is occured by commands like 'qtree' that traverse qdev > list. > > > > So, pci_qdev_init() returns -1 when init function returns not 0. > > > > Signed-off-by: SeokYeon Hwang > > Question: is there a simple way to trigger this error? You can reproduce this error by changing the return value of the unimportant device's init() to 1. Actually, I found this bug through the device that is not exist in upstream qemu. (It is Tizen emulator's device.) > > > --- > > hw/pci/pci.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 371699c..c149fdf 100644 > > --- a/hw/pci/pci.c > > +++ b/hw/pci/pci.c > > @@ -1766,7 +1766,7 @@ static int pci_qdev_init(DeviceState *qdev) > > rc = pc->init(pci_dev); > > if (rc != 0) { > > do_pci_unregister_device(pci_dev); > > - return rc; > > + return -1; > > } > > } > > > > -- > > 2.1.0