Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3765479pxt; Tue, 10 Aug 2021 10:48:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTAX9H5YG1gl/E9Kfrf01PB5ElKJqkRn8US9pCZoGD9+XgL9wa7nI7KFzSvG4F6TcaB1l0 X-Received: by 2002:a92:7d08:: with SMTP id y8mr492382ilc.111.1628617692486; Tue, 10 Aug 2021 10:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617692; cv=none; d=google.com; s=arc-20160816; b=d0gw6tiUyiVal8tCwgRIbNtOnEAT85qYYHonqBW13tkayvrRAZEk923zx9xf6WbVv4 xjoP2H0NSVTTHAPupWBBPJk5LMClSxaNSkqcQOqOTXxuwqs0r9FCKE708eZxWsMlSoV8 IoJcd2bOPyBEGoBWddrM6WV/z2S0b7Rpp5TZiIhK124l87tU4XCtS0tsAd4baYlkEPPd e9UfUi7pyaBdtb17bgQen1A2DuUwD1KWSugxxFHoAj32/7NFlJErGzvEM2u+OEQiXGl2 a7yLLiPU91PXRgQc7cm0QzOpKBllQu/Yt2ucYKBF2dcujXLKwlzBmGIk25SDFA6yQffk efOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sFhpoF0NdN4dImeUOSXN9nqNwriEDC01Zqs95Vy9xeY=; b=YZ7D3WT1JuR2gTn+mDDqcu1EYeGol+1DY2Mq8AeCkbovotAqbhySEiiDReAPc028dD mdDkaa21L55wpzXEJ50hzsNgnfHzWCgUMPHpW218mYrCoDxvF49AWyMJ/lSkcHOwHnIz e+EZ5UvqV51m1FQSVfUyJB0diwTvVV7mvU43pl+v4plEJ+BEfq1UKpzpVYoaE8qk00tT lii9uFdLOKMVYz3OC41SK+GCfZleCXFcWysOS2S+NK0rIrbWKWGywaHARuNffIkgzrmY 8H2gUBLaMANGrbr4jupGtQvmu3+4DHrj7cafsUo1w9IqkKyeatvU6K7uCTKgbxKN8vfL N4WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=onAjnEBg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si22708381ilo.41.2021.08.10.10.48.01; Tue, 10 Aug 2021 10:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=onAjnEBg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233062AbhHJRrl (ORCPT + 99 others); Tue, 10 Aug 2021 13:47:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:60974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234121AbhHJRnb (ORCPT ); Tue, 10 Aug 2021 13:43:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 523D961051; Tue, 10 Aug 2021 17:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617146; bh=WV751QS8Dg6MMKACD3XyQMswo5KtMnoOyo0FyT28e4Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=onAjnEBg8S4vxxRm07YvLWloE/Gk86yLPLvs+YDDA44BWLlYUY87za2HTNz/057/7 rcFsCisqatfBSfX36Zxlj6cr9emrHWObDCx5fhFYy3f5BNAbK0pwF/0p2fZ9qBSQs2 9dPMjfhtSeooEhVHu/kxm+66FTzyB++i7KDVapz4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felipe Balbi , Wesley Cheng Subject: [PATCH 5.10 064/135] usb: dwc3: gadget: Avoid runtime resume if disabling pullup Date: Tue, 10 Aug 2021 19:29:58 +0200 Message-Id: <20210810172957.870428170@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wesley Cheng commit cb10f68ad8150f243964b19391711aaac5e8ff42 upstream. If the device is already in the runtime suspended state, any call to the pullup routine will issue a runtime resume on the DWC3 core device. If the USB gadget is disabling the pullup, then avoid having to issue a runtime resume, as DWC3 gadget has already been halted/stopped. This fixes an issue where the following condition occurs: usb_gadget_remove_driver() -->usb_gadget_disconnect() -->dwc3_gadget_pullup(0) -->pm_runtime_get_sync() -> ret = 0 -->pm_runtime_put() [async] -->usb_gadget_udc_stop() -->dwc3_gadget_stop() -->dwc->gadget_driver = NULL ... dwc3_suspend_common() -->dwc3_gadget_suspend() -->DWC3 halt/stop routine skipped, driver_data == NULL This leads to a situation where the DWC3 gadget is not properly stopped, as the runtime resume would have re-enabled EP0 and event interrupts, and since we avoided the DWC3 gadget suspend, these resources were never disabled. Fixes: 77adb8bdf422 ("usb: dwc3: gadget: Allow runtime suspend if UDC unbinded") Cc: stable Acked-by: Felipe Balbi Signed-off-by: Wesley Cheng Link: https://lore.kernel.org/r/1628058245-30692-1-git-send-email-wcheng@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2132,6 +2132,17 @@ static int dwc3_gadget_pullup(struct usb } /* + * Avoid issuing a runtime resume if the device is already in the + * suspended state during gadget disconnect. DWC3 gadget was already + * halted/stopped during runtime suspend. + */ + if (!is_on) { + pm_runtime_barrier(dwc->dev); + if (pm_runtime_suspended(dwc->dev)) + return 0; + } + + /* * Check the return value for successful resume, or error. For a * successful resume, the DWC3 runtime PM resume routine will handle * the run stop sequence, so avoid duplicate operations here.