From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AAF855E5E; Wed, 21 Feb 2024 13:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708523565; cv=none; b=WQTs7l35toB5O0bP/30Zvc2n6vu5q2OcbWOFEZfo/KHA4WUvNdlA6BkVZ4fKtBY8AsRe8LaH66yzRMa3yTWqoZqYsikcDlm6G/GAFsc4yBkRFC+dEtybUeBsP0aP3Ci6ijT3SWEDHGJz684FGKz1sMxfvbHTf7X4Y3i+d+xGYCk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708523565; c=relaxed/simple; bh=4IPddyWVEUfRYKADp4PcwXWlVpXpfXsmM2TUVhUuZK8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jQivNKUiD+L6xzJxIkixrnSd5PEBMZ2MT0WcmpEXIdYVI46X9MEIZhSF0D5QpZhWQzwtzhO4eFCyFDYGJbflFX+rh8YWMQjJ6DgbKMceOtqT3zJCXot5BoAEq3aLL2JOBTTY0h3LPE3EGw05wvK1UB5B2CuH5LaTa/CGZDvrOvg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yA8t2b5C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="yA8t2b5C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7200C43142; Wed, 21 Feb 2024 13:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708523565; bh=4IPddyWVEUfRYKADp4PcwXWlVpXpfXsmM2TUVhUuZK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yA8t2b5COmDymJYATH1ptQi85GOE77OjDXGdS7LZWIJnSikYnotgE9vibopXv4q9+ 0RV/TYeq6x3WFyvtKOHZe6eZHasXo0Hqs3nmy97+2aJs2Y3cXd1oGZYbjQFlad/VhL Iv8jY71Lj5U6bxfH+kVZdkSd63m5DLynfERsBnTU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thinh Nguyen , Wesley Cheng Subject: [PATCH 5.15 474/476] usb: dwc3: gadget: Execute gadget stop after halting the controller Date: Wed, 21 Feb 2024 14:08:45 +0100 Message-ID: <20240221130025.513137333@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221130007.738356493@linuxfoundation.org> References: <20240221130007.738356493@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wesley Cheng commit 39674be56fba1cd3a03bf4617f523a35f85fd2c1 upstream. Do not call gadget stop until the poll for controller halt is completed. DEVTEN is cleared as part of gadget stop, so the intention to allow ep0 events to continue while waiting for controller halt is not happening. Fixes: c96683798e27 ("usb: dwc3: ep0: Don't prepare beyond Setup stage") Cc: stable@vger.kernel.org Acked-by: Thinh Nguyen Signed-off-by: Wesley Cheng Link: https://lore.kernel.org/r/20230420212759.29429-2-quic_wcheng@quicinc.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2517,7 +2517,6 @@ static int dwc3_gadget_soft_disconnect(s * bit. */ dwc3_stop_active_transfers(dwc); - __dwc3_gadget_stop(dwc); spin_unlock_irqrestore(&dwc->lock, flags); /* @@ -2547,7 +2546,19 @@ static int dwc3_gadget_soft_disconnect(s * remaining event generated by the controller while polling for * DSTS.DEVCTLHLT. */ - return dwc3_gadget_run_stop(dwc, false); + ret = dwc3_gadget_run_stop(dwc, false); + + /* + * Stop the gadget after controller is halted, so that if needed, the + * events to update EP0 state can still occur while the run/stop + * routine polls for the halted state. DEVTEN is cleared as part of + * gadget stop. + */ + spin_lock_irqsave(&dwc->lock, flags); + __dwc3_gadget_stop(dwc); + spin_unlock_irqrestore(&dwc->lock, flags); + + return ret; } static int dwc3_gadget_soft_connect(struct dwc3 *dwc)