From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:56575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbFmF-0007F1-Uw for qemu-devel@nongnu.org; Thu, 15 Dec 2011 13:11:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RbFmE-0007EP-NG for qemu-devel@nongnu.org; Thu, 15 Dec 2011 13:11:31 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:32892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbFmE-0007EH-K3 for qemu-devel@nongnu.org; Thu, 15 Dec 2011 13:11:30 -0500 Received: by iagj37 with SMTP id j37so3556647iag.4 for ; Thu, 15 Dec 2011 10:11:30 -0800 (PST) Message-ID: <4EEA384E.5020300@redhat.com> Date: Thu, 15 Dec 2011 12:11:26 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1323943518-7546-1-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1323943518-7546-1-git-send-email-stefanha@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] usb: fix usb_qdev_init() error handling again List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Erik Rull <904617@bugs.launchpad.net>, qemu-devel@nongnu.org, Gerd Hoffmann On 12/15/2011 04:05 AM, Stefan Hajnoczi wrote: > Commit f462141f18ffdd75847f6459ef83d90b831d12c0 introduced clean up code > when usb_qdev_init() fails. Unfortunately it calls .handle_destroy() > when .init() was never invoked or failed. This can lead to crashes when > .handle_destroy() tries to clean up things that were never initialized. > > This patch is careful to undo only those steps that completed along the > usb_qdev_init() code path. It's not as pretty as the unified error > handling in f462141f18ffdd75847f6459ef83d90b831d12c0 but it's necessary. > > Signed-off-by: Stefan Hajnoczi Applied. Thanks. Regards, Anthony Liguori > --- > hw/usb-bus.c | 12 +++++------- > 1 files changed, 5 insertions(+), 7 deletions(-) > > diff --git a/hw/usb-bus.c b/hw/usb-bus.c > index 8cafb76..8203390 100644 > --- a/hw/usb-bus.c > +++ b/hw/usb-bus.c > @@ -77,23 +77,21 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) > QLIST_INIT(&dev->strings); > rc = usb_claim_port(dev); > if (rc != 0) { > - goto err; > + return rc; > } > rc = dev->info->init(dev); > if (rc != 0) { > - goto err; > + usb_release_port(dev); > + return rc; > } > if (dev->auto_attach) { > rc = usb_device_attach(dev); > if (rc != 0) { > - goto err; > + usb_qdev_exit(qdev); > + return rc; > } > } > return 0; > - > -err: > - usb_qdev_exit(qdev); > - return rc; > } > > static int usb_qdev_exit(DeviceState *qdev)