From patchwork Mon Aug 9 22:31:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 12427445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA7D2C432BE for ; Mon, 9 Aug 2021 22:32:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB7BE60E76 for ; Mon, 9 Aug 2021 22:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236734AbhHIWc0 (ORCPT ); Mon, 9 Aug 2021 18:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233565AbhHIWc0 (ORCPT ); Mon, 9 Aug 2021 18:32:26 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83AE7C0613D3 for ; Mon, 9 Aug 2021 15:32:05 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id w13-20020a17090aea0db029017897a5f7bcso2267764pjy.5 for ; Mon, 09 Aug 2021 15:32:05 -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=NzjcRfEcACJvgTVpHXjAyUs8UkB1tiZkWLbrVQy12/Q=; b=lCeiJTQknowjGfNbQ7NgspnLemPOUVn1UFwleOgZ4LEWrQA4rxLT/TgvxY+b09YLAM 8W2JTMDxAPXYwsa3HMlpXlo7bLCBE1FIJt4oScW8PSWY4IbA+tkRBuCIjWKKGE30HnzV 5IL8ctqS7sgFHbHCXKBk/BtnYPBMbsLzMn9i5LKFzM+Q7mKl1fqYndx8Ayadu+zZEa0T zGzo2QrVXImVJPKmVB4nu5xYF+YV0OrMzbbP20/sPybAf9HXogBSvpHKIjakVElD8cd0 eFFCg3qK2R89ox8dNg66yyRp6ikD5OQPfD7nUa8y8sSAEZNSNoTJluZFeNYS4+4CwixC exmA== 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=NzjcRfEcACJvgTVpHXjAyUs8UkB1tiZkWLbrVQy12/Q=; b=tBw31FvtSQSnpeIus4n2wNXDpeXlwSjpxLzdkuJLd4PE2b+QX238l/oaE6YGVbma9T MxkFUzclgJkPIzjalcf2E1Z8YCQyWsW5ZGjAJSb40V7e4nXBADarU0pD2jTaJHRY1hdG SYfzu0P9U/IMIXh6jmGCRMkXrqjM4fC8YiXX1ZISnSQYW8YparnQA+VcW9DCPw06NDcC 4sFhJxvPNca9Ls4NBS7/4qMrCaFV6YEQfU36a57zaRXxzH7bEhk9ac24c8W3zTSSjZHW cPVj8d9NFBgz8fP5p5r44hoVoyUxvvwdkSnqFKHsGcEygvCX/Ad6jBfBjTshLNGGslrM r3jg== X-Gm-Message-State: AOAM5308sbYR0F+dCt8GWrWnPQ8av6Zx4PxF5zMoCCiYwmWPkCHUgQMV xIB8olUAcWLrLjqNdW7H5C/ELw== X-Google-Smtp-Source: ABdhPJxElfD99iLkdqdtMOOjJGVjntQCDrUuzUrKYce2aY57R9QMXv0KBqjCPSJ4IkXYSZ+4NCvvUw== X-Received: by 2002:a05:6a00:c81:b029:30e:21bf:4c15 with SMTP id a1-20020a056a000c81b029030e21bf4c15mr26160813pfv.70.1628548325071; Mon, 09 Aug 2021 15:32:05 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id x26sm21276226pfm.77.2021.08.09.15.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 15:32:04 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Wesley Cheng , Felipe Balbi , Greg Kroah-Hartman , Alan Stern , Jack Pham , Thinh Nguyen , Todd Kjos , Amit Pundir , YongQin Liu , Sumit Semwal , Petri Gynther , linux-usb@vger.kernel.org Subject: [RFC][PATCH] dwc3: gadget: Fix losing list items in dwc3_gadget_ep_cleanup_completed_requests() Date: Mon, 9 Aug 2021 22:31:59 +0000 Message-Id: <20210809223159.2342385-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In commit d25d85061bd8 ("usb: dwc3: gadget: Use list_replace_init() before traversing lists"), a local list_head was introduced to process the started_list items to avoid races. However, in dwc3_gadget_ep_cleanup_completed_requests() if dwc3_gadget_ep_cleanup_completed_request() fails, we break early, causing the items on the local list_head to be lost. This issue showed up as problems on the db845c/RB3 board, where adb connetions would fail, showing the device as "offline". This patch tries to fix the issue by if we are returning early we splice in the local list head back into the started_list and return (avoiding an infinite loop, as the started_list is now non-null). Not sure if this is fully correct, but seems to work for me so I wanted to share for feedback. Cc: Wesley Cheng Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: Alan Stern Cc: Jack Pham Cc: Thinh Nguyen Cc: Todd Kjos Cc: Amit Pundir Cc: YongQin Liu Cc: Sumit Semwal Cc: Petri Gynther Cc: linux-usb@vger.kernel.org Fixes: d25d85061bd8 ("usb: dwc3: gadget: Use list_replace_init() before traversing lists") Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index b8d4b2d327b23..a73ebe8e75024 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2990,6 +2990,12 @@ static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep, break; } + if (!list_empty(&local)) { + list_splice_tail(&local, &dep->started_list); + /* Return so we don't hit the restart case and loop forever */ + return; + } + if (!list_empty(&dep->started_list)) goto restart; }