From patchwork Thu Apr 19 09:46:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 153715 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A687FB6FF1 for ; Thu, 19 Apr 2012 19:47:15 +1000 (EST) Received: from localhost ([::1]:59670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKnxI-0004uv-8U for incoming@patchwork.ozlabs.org; Thu, 19 Apr 2012 05:47:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKnx7-0004uj-8n for qemu-devel@nongnu.org; Thu, 19 Apr 2012 05:47:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKnx0-0004Ab-1G for qemu-devel@nongnu.org; Thu, 19 Apr 2012 05:47:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17491) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKnwz-0004AP-Pa for qemu-devel@nongnu.org; Thu, 19 Apr 2012 05:46:53 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3J9kq6O028827 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Apr 2012 05:46:52 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3J9kpIx004916; Thu, 19 Apr 2012 05:46:51 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id B37EF405D2; Thu, 19 Apr 2012 11:46:50 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 19 Apr 2012 11:46:50 +0200 Message-Id: <1334828810-14291-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH] usb-storage: fix request canceling 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 Little fix for usb packet handling on i/o cancelation. The usb packet pointer (s->packet) is cleared at the wrong place: The scsi request cancel handler does it. When a usb packet is canceled the usb-storage emulation canceles the scsi request if present. In most cases there is one, so usually s->packet is cleared as needed even with the code sitting at the wrong place. If there is no scsi request in flight s->packet is not cleared though. The usb-storage emulation will then try to complete an usb packet which is not in flight any more and thereby trigger an assert() in the usb core. Fix this by clearing s->packet at the correct place, which is the usb packet cancel header. Signed-off-by: Gerd Hoffmann Acked-by: Hans de Goede Reviewed-by: Paolo Bonzini --- hw/usb/dev-storage.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index d865a5e..3d2f244 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -268,7 +268,6 @@ static void usb_msd_request_cancelled(SCSIRequest *req) if (req == s->req) { scsi_req_unref(s->req); s->req = NULL; - s->packet = NULL; s->scsi_len = 0; } } @@ -330,6 +329,9 @@ static void usb_msd_cancel_io(USBDevice *dev, USBPacket *p) { MSDState *s = DO_UPCAST(MSDState, dev, dev); + assert(s->packet == p); + s->packet = NULL; + if (s->req) { scsi_req_cancel(s->req); }