From patchwork Thu Aug 12 17:16:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 496041 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp595504jap; Thu, 12 Aug 2021 10:17:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkQmWhP6TAI47Inwx4PH1e6DBQ0TnvuOOHIPUojDnOiCr6c7521QKt7Jsosy4x9Mhovzl6 X-Received: by 2002:a17:906:769a:: with SMTP id o26mr4764045ejm.18.1628788631742; Thu, 12 Aug 2021 10:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628788631; cv=none; d=google.com; s=arc-20160816; b=sS/jleAVi1j3aALbLyQCQpNtqXn7l55xrtpqhab3hgNWc76SVmruKTzR/sZWZIiKWN 0d/qzFNuDyBhsSt7tHKFhCK2T/2TTaMQr8zASs+2s8OlhFKTHaXlR0G/kIKhG/IWjOMh DiyVeI235w5VkOB2bcdf9DeIInnPPkqmvN5lZESDm7fkOaI8hhuAhAzfKaUTSqZ/mES1 N9mxSHMyoYks1nkFVti2alYK7jP2/vJrvREjh0bp0AuUQmu21jvfY+gnO0BVWM/1EjVO /lo5qxvs+UIadyuE3YkRZxhkh2aNam7QCFXZazk3jtiPVY8weuQqjxHUvX2rTxvkYGQ4 SVPw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LjrU9k0cXOS1w5BQXAwU+RejY/N5vivrkzc/UFmCECk=; b=hRuWTXW90Vh++6t9zrUlNbjCmX135/PLaSMGfZayTDNXkD7w674Jlt00gsapKo0ibC iupAUI3RliiQ9D7vy3FDsoM9LIAtngTCovaJgkrAv+4tUobRwe8OTYeKKF0gjeoDtb3R 4qOvt8qCTXsrRFa5hNJjAOdCg/GRu90DFdPLfvuA3OiTy684lbS/FJ9VtpBaJ/tkYMWz QqTLUwmJQqU2MARGyZkW981MG29+a4RlrlYfE0B1/zuNT1jEX9Px2Rj2J5TCp+a9MTJO jJaSXLl0PLtCLg1ceheAbVlNlBlHiKT8IS7WAunVoISCRuBkVSZhCOHSQpHtFukPKJTj tOyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vXvZTM5p; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si3226044edy.351.2021.08.12.10.17.11; Thu, 12 Aug 2021 10:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@linaro.org header.s=google header.b=vXvZTM5p; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235327AbhHLRRc (ORCPT + 12 others); Thu, 12 Aug 2021 13:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235044AbhHLRRb (ORCPT ); Thu, 12 Aug 2021 13:17:31 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55787C061756 for ; Thu, 12 Aug 2021 10:17:06 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id t9so14793267lfc.6 for ; Thu, 12 Aug 2021 10:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LjrU9k0cXOS1w5BQXAwU+RejY/N5vivrkzc/UFmCECk=; b=vXvZTM5pSgzHzFrb56dPXE5fgDfw8i5/bcwGF/ZwWb4JEClBcZAe2v9pLNMa3hRCVN Aaod/ovXAexrExrElPgAWlAAHUglUkkwFAUmR5qsrSucybv+8p6z/DJOUEeS7vQSoreB EvM+gPAg0GftW98ZOrhHaTVwJNeQhomw76bJCCmSUYsl9RkvkCU5B2pI2GdmOENLLkAM G6MrHR5yKbDjLOgU9rTsp+oRlNTj7/CW/yruhlXBcp6BsPtRX3jLtYx1VrmWlAt237o1 TgCnadyKwuuwwcFGYflx+QJfocS/6MpB4DBOa0CT9JePBypms9TnkHVBaw9edXp/2peS Wacg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LjrU9k0cXOS1w5BQXAwU+RejY/N5vivrkzc/UFmCECk=; b=YFu9yi5eFfTepabfdP77mv+7/9XyCUUGaPnPPIlUx8lnGrm3v3jyHtJwbybvlNvj/V rX4OXxI724LQe+yN9WE2N5lKcYm4u4bHjfUVToSQdfnLghPnDWdapDCSNlpZgKoDsxu+ Cdl6B9jSnvNW5ajxf62cg2w/kI19223/8Vcu4DVGyGTqFGoM7DWAYdgeQkOVyID5DwaF gYI9Dm9Qgu12P5cx5QYne2s7bJKCCA0cZF5fEYGpuSk4NKqe0L9bkTyxPaTANGqERuHA cVR0KN3oQ/dIdtyLpljFoPYk6TAcO2FcZpVG1ubih7vJ8h6UabIJZ2zquYKGCKmVLTGn PKEg== X-Gm-Message-State: AOAM5312jUiEIBRVemjoINHzrD0bujLF3gdIs+oUflrCEXjadn8PBCgO 4sYgdZigjrRXbakkM6l0zvHBUg== X-Received: by 2002:ac2:4852:: with SMTP id 18mr862714lfy.214.1628788624697; Thu, 12 Aug 2021 10:17:04 -0700 (PDT) Received: from localhost ([31.134.121.151]) by smtp.gmail.com with ESMTPSA id u10sm316738lft.252.2021.08.12.10.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 10:17:04 -0700 (PDT) From: Sam Protsenko To: Greg Kroah-Hartman Cc: stable@vger.kernel.org, Wesley Cheng Subject: [PATCH 5.4 7/7] usb: dwc3: gadget: Avoid runtime resume if disabling pullup Date: Thu, 12 Aug 2021 20:16:52 +0300 Message-Id: <20210812171652.23803-8-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812171652.23803-1-semen.protsenko@linaro.org> References: <20210812171652.23803-1-semen.protsenko@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Wesley Cheng [ Upstream commit cb10f68ad8150f243964b19391711aaac5e8ff42 ] 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(+) -- 2.30.2 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 78a4b9e438b7..8a3752fcf7b4 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2018,6 +2018,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) } } + /* + * 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