Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp489041imn; Wed, 3 Aug 2022 12:29:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR4By+Z8XlkaET8PjUTpDkvd7MtRVKFw/ZHYZcK0oANw7EmsF3d7n6L1BZt/EqwZFucR4sFQ X-Received: by 2002:aa7:dbca:0:b0:43e:6707:d298 with SMTP id v10-20020aa7dbca000000b0043e6707d298mr1563794edt.133.1659554975039; Wed, 03 Aug 2022 12:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659554975; cv=none; d=google.com; s=arc-20160816; b=sF/gJQJvzOadrDTJynVD09uQ8gD2/59y9Cpcoz6Tyt9TOPWB5W9g8vDUTtyndHZg2X c4erI4wNMfVKMSw9+Yrq7AYZpaLTO0J3NeQnU4r42oOrneF0Q48pXjZe0u9u/kw7yAe4 K/sTcnU8EVZE/v0tYbpMQlYtpz5lligTFW0hR2Ob1thRPV7bqmRzFolM7Dc/rzee6JhZ 6GGFenNFBvM8CWSenP5yuLgl8Lf57XlJXlDgbOT41x/tzncZI+WiKii4Zd04yrQC9kri EZ1owYahyPrHgWH1QUajIF6Ncp7St+xc76RaBMgUU30+WCI5tHLbPLf8+AaRIuX9z9+a RShg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Yem/qpYgEmCA72j+50vuDoYqx1yqH6LmWKyXF9t4QJg=; b=pJHLXsKdIROl86tT/JSRiDnPHIJ0QeeHjNAdU6/QjltQF90oWX3e2nbSJ/cbM1RgUu SKpaJPM8PgSykIcLwkSnK/3Ifd+W6v9rtBCfvkMq9FEjetsBa4rp9uV3XADUdCRCGQCN ptWMiTLaH8sUCb9HtsfuS+2Cnq9ZI6AUokPZYxe4RVisqk43g3RezK5TwBuLIwMmKoL2 +VRLrsg37XJwKgderHQd7Nk5RDuHXOBnvfHmehPbaWJ3GN7AwIskifGh86yflKxGkN2P MlTCA9Oey3ddWAIDFIxZAAVu/hYS2Ra45g/RfUnqWbEt7OXHTMfMLDTI8Nl/Td53A0di MhEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EwxcoNIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a170906a11400b00726a3abf022si3503789ejy.781.2022.08.03.12.29.10; Wed, 03 Aug 2022 12:29:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EwxcoNIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238422AbiHCTLr (ORCPT + 99 others); Wed, 3 Aug 2022 15:11:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiHCTLp (ORCPT ); Wed, 3 Aug 2022 15:11:45 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44170186F9 for ; Wed, 3 Aug 2022 12:11:44 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id w14so4227218plp.9 for ; Wed, 03 Aug 2022 12:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Yem/qpYgEmCA72j+50vuDoYqx1yqH6LmWKyXF9t4QJg=; b=EwxcoNIv8M8nBbi4W52JGeZOlI+IHvVO1zFTLNFcaeZacJh9+EWETN98RqBn/VQxu6 tCrof60TWxBkZ5GDGErF9ZuxvR8nwF+2Pc/wZrDG1ZNQg3Qg+n2XVZsdsY8DPBEuS72x QQ29+MDE/K9tTT1pexxtQ+L7ZNYHVNzt0AB6s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Yem/qpYgEmCA72j+50vuDoYqx1yqH6LmWKyXF9t4QJg=; b=h2ZUV+VpdhGKBKhcvst7TLU7buPKvSyplodBqs5uLscS94Y2YBGx1QelekbH6iy8B3 mpCeCWQ+sVO4yeQ/I4ZEcC4ZOXUtYh+WnwXx3V4Ha6eB/0mseFSelGzIzp53aoVkOa2W bm7h6trjRDd1Zxu4b4A/xytoORZyibjzqrqtgFuDc0nVkE8D6J7fBYdN/qGFm2fnIbv+ losxoBTsk1RAO+2U6p79Vy7/jQBui6rgBhQ+BCKFMDtYAOgDoauhZsbKEHux/CMfa9Ff 0bScbUG5j4I+71/euoeoDkOcw+2MDsDwbSOZE+UQGSx3AvwJILrQEwBs/YXHbMdD7cgP /NCA== X-Gm-Message-State: ACgBeo2rrE75kdm8LfOLTHAPh9cj3hw5psvL8zzW7raYs34dXry/w1P8 bnAT/uSHrq8BABAKCHB5rjxLRw== X-Received: by 2002:a17:90b:1c0a:b0:1f3:1848:591c with SMTP id oc10-20020a17090b1c0a00b001f31848591cmr6248533pjb.24.1659553903773; Wed, 03 Aug 2022 12:11:43 -0700 (PDT) Received: from localhost ([2620:15c:11a:202:238b:c074:f5f8:56d0]) by smtp.gmail.com with UTF8SMTPSA id k15-20020a170902c40f00b0016dbaf3ff2esm2456247plk.22.2022.08.03.12.11.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Aug 2022 12:11:43 -0700 (PDT) Date: Wed, 3 Aug 2022 12:11:41 -0700 From: Matthias Kaehlcke To: Johan Hovold Cc: Greg Kroah-Hartman , Felipe Balbi , Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/8] usb: dwc3: qcom: fix broken non-host-mode suspend Message-ID: References: <20220802151404.1797-1-johan+linaro@kernel.org> <20220802151404.1797-4-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220802151404.1797-4-johan+linaro@kernel.org> X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 02, 2022 at 05:13:59PM +0200, Johan Hovold wrote: > A recent commit implementing wakeup support in host mode instead broke > suspend for peripheral and OTG mode. > > The hack that was added in the suspend path to determine the speed of > any device connected to the USB2 bus not only accesses internal driver > data for a child device, but also dereferences a NULL pointer when not > in host mode and there is no HCD. > > As the controller can switch role at any time when in OTG mode, there's > no quick fix to this, and since reverting would leave us with broken > suspend in host-mode (wakeup triggers immediately), keep the hack for > now and only fix the NULL-pointer dereference. > > Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend") > Signed-off-by: Johan Hovold > --- > drivers/usb/dwc3/dwc3-qcom.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c > index be2e3dd36440..b75ff40f75a2 100644 > --- a/drivers/usb/dwc3/dwc3-qcom.c > +++ b/drivers/usb/dwc3/dwc3-qcom.c > @@ -301,8 +301,17 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom) > static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom) > { > struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); > - struct usb_hcd *hcd = platform_get_drvdata(dwc->xhci); > struct usb_device *udev; > + struct usb_hcd *hcd; > + > + if (qcom->mode != USB_DR_MODE_HOST) > + return USB_SPEED_UNKNOWN; Couldn't instead the below block in dwc3_qcom_suspend() be conditional on the controller being in host mode? if (device_may_wakeup(qcom->dev)) { qcom->usb2_speed = dwc3_qcom_read_usb2_speed(qcom); dwc3_qcom_enable_interrupts(qcom); } I see, the problem is that the role switch could happen at any time as the commit message says. With this patch there is also a race though, the role switch could happen just after the check and before obtaining 'hcd'.