Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3775194pxt; Tue, 10 Aug 2021 11:02:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvuoXeFixNzg+SPGSODhOSt5YHH2cg4u/5c4ih392D5PLh3JJNCd73MNt6s+mQsQD0rPeF X-Received: by 2002:a17:906:b750:: with SMTP id fx16mr28619520ejb.108.1628618574679; Tue, 10 Aug 2021 11:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628618574; cv=none; d=google.com; s=arc-20160816; b=bqhRyW6+YQZguMxS8AotU3HQEM8hagSjeYBEpBcFIeVOEaAc4hHxS/rTHFAj+Xld+I 57PiDq9nb0Twb5EXBTchcPzl1Ld7LmBS2UbSjxIRmmG8RLF+Vrcx9VdcqpXykZA8j173 WJOwpREUkzhl3EgoC3h+wXyKgEPW9YAqa9mLWyyiAUFjlVAOR/jCyRDTmQTayFZuo9Bm iKYzplbOgeACk73O/E7LXtGbuOcZVIqCsv6yVwrqqbHGdaiFz5AQaXfbVmGRkDdd2vl3 Cu+RcnGZolCbYiPZjJ81EpTP+Iht79R9TX8yRT9rlitPks8xyBlxboQQPnXpXIqFS7Ha pEYw== 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=bmi+WrEXF+EthBWo2aI5elRDk9wCmojuU45vFBrszkg=; b=G+atob8Iydf3LFKvgaBfr9ez7VigFd2gHcOyU0q0sytEWks+EIjWdbj/67F61wB2Yj NH61kM2efNQtgxSPyNbiFmhxDkNv0Zi10SbM3V0V+SvF5CYbsjWmqB1Y9E+FrwkBBXOF 7Oc7IYJGhHuvdUkkK45/LczGqWacyHxfh5DGK4f5iK6VBR9U14+z9RAOKPOyAxfBcY8g eGFIHk0frVMIrahqmz38HTLzfc16vj79PdzNMOL7cRLpvzNDAA/SpEGjL6ceTiJ/+cIc OV2EMfR0vH59f1wAiLoA+wrxc6SLzbqkmF91yiEomHEWv5nyaapi52BhivxCzS8BSwPD nspw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mO94tx+O; 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 ji2si21236423ejc.344.2021.08.10.11.02.29; Tue, 10 Aug 2021 11:02:54 -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=mO94tx+O; 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 S237286AbhHJSA1 (ORCPT + 99 others); Tue, 10 Aug 2021 14:00:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:51490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237163AbhHJR4q (ORCPT ); Tue, 10 Aug 2021 13:56:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F8F0610FC; Tue, 10 Aug 2021 17:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617512; bh=sJcqfH1Q4IrnK/z7vHlXFzLXPIrHRa2rRBS6dIPiPA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mO94tx+Ou0B6cXNbF0lluSz4layUZKbGybdULBKViaEmjoeXo0k5/mdHpZxUI+2cl 5I6bJEHGVjE9YWRT/Jpl7sVirqWJHn6SBSagnjHcZgHwPOc5Uk3a78H17SbloMUIMx WCCraXe6/NPQfyqaFY4gLc/L+0YeSUXj2VO3uD4U= 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.13 090/175] usb: dwc3: gadget: Avoid runtime resume if disabling pullup Date: Tue, 10 Aug 2021 19:29:58 +0200 Message-Id: <20210810173003.905650577@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810173000.928681411@linuxfoundation.org> References: <20210810173000.928681411@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 @@ -2257,6 +2257,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.