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 34C259443 for ; Sun, 13 Aug 2023 21:21:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B14CFC433C7; Sun, 13 Aug 2023 21:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1691961705; bh=/vy778I+Awk3J4osGPEOleSxsUAMIJ8ZAIcl4mrJOeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3qLbunSW89EhW2Ee8xzs6ysIc6oEk/kHgWFJA/ftnjJWCwP7Y7S7rYbfdw3Bsqdo +1TIJy3WXognAueB1ipMeGkbCrMyQ3dwkTkpBivBORWi/erwP7W8RBMQGiN0MGKIJV PF0Pgr765cSDl8hmzE9zRdTsAYkMSSsR4lN62/kc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Elson Roy Serrao , Thinh Nguyen , Roger Quadros Subject: [PATCH 4.14 10/26] usb: dwc3: Properly handle processing of pending events Date: Sun, 13 Aug 2023 23:19:03 +0200 Message-ID: <20230813211703.382011333@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230813211702.980427106@linuxfoundation.org> References: <20230813211702.980427106@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Elson Roy Serrao commit 3ddaa6a274578e23745b7466346fc2650df8f959 upstream. If dwc3 is runtime suspended we defer processing the event buffer until resume, by setting the pending_events flag. Set this flag before triggering resume to avoid race with the runtime resume callback. While handling the pending events, in addition to checking the event buffer we also need to process it. Handle this by explicitly calling dwc3_thread_interrupt(). Also balance the runtime pm get() operation that triggered this processing. Cc: stable@vger.kernel.org Fixes: fc8bb91bc83e ("usb: dwc3: implement runtime PM") Signed-off-by: Elson Roy Serrao Acked-by: Thinh Nguyen Reviewed-by: Roger Quadros Link: https://lore.kernel.org/r/20230801192658.19275-1-quic_eserrao@quicinc.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3172,9 +3172,14 @@ static irqreturn_t dwc3_check_event_buf( u32 reg; if (pm_runtime_suspended(dwc->dev)) { + dwc->pending_events = true; + /* + * Trigger runtime resume. The get() function will be balanced + * after processing the pending events in dwc3_process_pending + * events(). + */ pm_runtime_get(dwc->dev); disable_irq_nosync(dwc->irq_gadget); - dwc->pending_events = true; return IRQ_HANDLED; } @@ -3414,6 +3419,8 @@ void dwc3_gadget_process_pending_events( { if (dwc->pending_events) { dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); + dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf); + pm_runtime_put(dwc->dev); dwc->pending_events = false; enable_irq(dwc->irq_gadget); }