From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBE38EB64D9 for ; Mon, 19 Jun 2023 10:53:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232258AbjFSKxz (ORCPT ); Mon, 19 Jun 2023 06:53:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjFSKxU (ORCPT ); Mon, 19 Jun 2023 06:53:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E37A35B8 for ; Mon, 19 Jun 2023 03:51:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A871A60B7F for ; Mon, 19 Jun 2023 10:51:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE5EFC433C9; Mon, 19 Jun 2023 10:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687171913; bh=9oYWW/6djlH0ZwigY8yLRZYn8X/oqV+/KtyTLo4wYXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W9uwLX37rfwIU4XLaNBwUvuT7U8YI3VomyAkV2uFqUkDIDBMzCSvgYXCaXVCoVQcL 7G8R+/363f2sL55PAkoSR0WTjYWOYo0ktXUp8eQSwrTxqsBnwE3BbH6bO/xi4kGjvP P1DrvbFKIep/JFAQWabZ8Mq4c8Kiizt1QLPjCEXo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Elson Roy Serrao , Thinh Nguyen Subject: [PATCH 5.4 35/64] usb: dwc3: gadget: Reset num TRBs before giving back the request Date: Mon, 19 Jun 2023 12:30:31 +0200 Message-ID: <20230619102134.761525873@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230619102132.808972458@linuxfoundation.org> References: <20230619102132.808972458@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Elson Roy Serrao commit 00f8205ffcf112dcef14f8151d78075d38d22c08 upstream. Consider a scenario where cable disconnect happens when there is an active usb reqest queued to the UDC. As part of the disconnect we would issue an end transfer with no interrupt-on-completion before giving back this request. Since we are giving back the request without skipping TRBs the num_trbs field of dwc3_request still holds the stale value previously used. Function drivers re-use same request for a given bind-unbind session and hence their dwc3_request context gets preserved across cable disconnect/connect. When such a request gets re-queued after cable connect, we would increase the num_trbs field on top of the previous stale value thus incorrectly representing the number of TRBs used. Fix this by resetting num_trbs field before giving back the request. Fixes: 09fe1f8d7e2f ("usb: dwc3: gadget: track number of TRBs per request") Cc: stable Signed-off-by: Elson Roy Serrao Acked-by: Thinh Nguyen Message-ID: <1685654850-8468-1-git-send-email-quic_eserrao@quicinc.com> Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -177,6 +177,7 @@ static void dwc3_gadget_del_and_unmap_re list_del(&req->list); req->remaining = 0; req->needs_extra_trb = false; + req->num_trbs = 0; if (req->request.status == -EINPROGRESS) req->request.status = status;