From patchwork Thu Dec 15 10:05:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 131552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 81B491007D6 for ; Thu, 15 Dec 2011 21:06:10 +1100 (EST) Received: from localhost ([::1]:40895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rb8CV-0002qK-FW for incoming@patchwork.ozlabs.org; Thu, 15 Dec 2011 05:06:07 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rb8CH-0002q6-Nh for qemu-devel@nongnu.org; Thu, 15 Dec 2011 05:06:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rb8CB-0001ed-1a for qemu-devel@nongnu.org; Thu, 15 Dec 2011 05:05:53 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:54140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rb8CA-0001XC-8h for qemu-devel@nongnu.org; Thu, 15 Dec 2011 05:05:46 -0500 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 15 Dec 2011 10:05:40 -0000 Received: from d06nrmr1806.portsmouth.uk.ibm.com ([9.149.39.193]) by e06smtp11.uk.ibm.com ([192.168.101.141]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 15 Dec 2011 10:05:30 -0000 Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBFA5T6l2211890 for ; Thu, 15 Dec 2011 10:05:29 GMT Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBFA5Sw2019824 for ; Thu, 15 Dec 2011 10:05:29 GMT Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pBFA5RcK019749; Thu, 15 Dec 2011 10:05:27 GMT From: Stefan Hajnoczi To: Date: Thu, 15 Dec 2011 10:05:18 +0000 Message-Id: <1323943518-7546-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 x-cbid: 11121510-5024-0000-0000-00000119A8DB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.107 Cc: Erik Rull <904617@bugs.launchpad.net>, Gerd Hoffmann , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] usb: fix usb_qdev_init() error handling again 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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)