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: 493983 Delivered-To: patches@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp3340789jap; Mon, 9 Aug 2021 15:32:05 -0700 (PDT) X-Received: by 2002:a17:902:a705:b029:12b:71be:d24e with SMTP id w5-20020a170902a705b029012b71bed24emr10446324plq.29.1628548325465; Mon, 09 Aug 2021 15:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628548325; cv=none; d=google.com; s=arc-20160816; b=WSxDUgMElSrgjPGaXaEe9hqzwmEq4jUoN0QC01yT3f+NMj0Et15iVh3xl4DoYQXvqn WsDFs2M2Bq04SFSv7FbyFZxOVRO3Xl7JTijc9r64pzB/W+mL0DJgsZZnkU4q3jwVCTDd Ibxz6wiW47PNZBgZULmwJBXaTqw5mOlLa58Z1bwBuRi2SLOZPMW2Nx9V61sBFFvxbXqv XTZxox+drtd7IZJItrSSi2DDMnJ48M8tyQaVFWMMp+qaP3lSQgnkQiXpIR9kSgN2uXgc d5g6k9Hdttyu5e13kqLyLKJPLhLLLrZVctuCpSG4mpkd4wMZdHQilOz9M/JarsxWU9hd drPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=NzjcRfEcACJvgTVpHXjAyUs8UkB1tiZkWLbrVQy12/Q=; b=ridMoyknr/3U0IDJP21cj2psRcP5a8gqAr2QhoZuHkbf9CI14XpjzcT0tn/OdkHXY7 fLM489iWFHYNaDantF4hFRaquJEe5G5sk+LRCucpYnUm1Ze5GAXkSSQeGKzRj/m1ZQAe Hd0ahGzAtVhTx/h7v8HCiKdgBhK35bcLofjpaa+PkVMfKp5h5a4MD+YIbPRGybSVGwdH JEGv57hOpSoHSdjgFxchBzgu89R/oVrRJpK53Q077TfIIJLprMqENNAhxVzt6Xw50l5X 8iJHI3Gvu6hVa9bQdNh/9KIeKrG8iUHimtjadhkI4f/bO99cPwuWh1BUS5Ac9f7N5Be3 0O7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lCeiJTQk; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id d145sor478444pfd.80.2021.08.09.15.32.05 for (Google Transport Security); Mon, 09 Aug 2021 15:32:05 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lCeiJTQk; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=HrC7eZij9+2yodQEd/PGIurRq1mMrK/o/UoYc9GpH7pYptalJx4l6R+VSS/pEdro36 Mi1y/J01wYFG3TzzbqBkCYKysPmWsD50SNxc2f7AKKgPnjOK/zJdnVh14NoGD6wW8fRn r+M/FIYR67MGWcgz4XY4a+NfZGruwvhw4ykqM+obMIdi2LN9u2Z/QHbdiQeP6Fbjh2b4 ryh6M1XeCXvUP5OXLEk5SJdNWZX1cf1b1ii0gxop87svcfbHM0og8Yxmbm7JeyHcE0BO 1+3gkjARHmEH/aKEwVr0LAKgKAPxSgyED/lEk+epCRqFsSWdHJAj56EUX2cHsp4eP0Wz xGbA== X-Gm-Message-State: AOAM530ZRkMC0Bkbxi2rfs5nIgfOm+Ha1kV8EGIMW+FQRAoq+6tLhcbu MmYpNn/mbwwtEPsVJ7QIOsfuo4k3 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) Return-Path: 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 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(+) -- 2.25.1 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; }