Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1947825imm; Thu, 24 May 2018 03:25:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo346dQta3yfxgRQUsCSDNEW7VgSvHF1kWsRFNQvVQwr4ElkK3un2qGQJfqqBjkoR/1Qxaz X-Received: by 2002:a17:902:20e5:: with SMTP id v34-v6mr6777281plg.127.1527157558729; Thu, 24 May 2018 03:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527157558; cv=none; d=google.com; s=arc-20160816; b=doSk6N0qi9UEyFyyNhwX5hb4jXRcZDqS0QAQ6egj2xB9qFqJE6NbC1zYkXSNwoqYLH +drC/qSA7pQJXMmzaMlmQpwt0Z4LLTyRN3nPHWgnj/40fTe0Bm7mm+TXWdcuHvAKy8la KiZ0hCouNQEHvFn8Itbi5z/hhzPxvKdaWV+4VWnLYmOBnqJRqUryox3flx+vOYayZG1y aKm8U3ntfDnEWkPG2YkhE74sxjub3YgCtHRoc8wGCuwv+qbnkLtTM8yNLL6a8Q1WxcCj aBs7hURbjHiqQt3VrsGpUYrbo74Fepj1AQ8sE6fcKd9W4KIjpqYApLZkUg4hUNYnq6X7 FSug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=yBQCLnzM7k6J+IFVXCFZCM/TiGk2BGGOqT9mbJKQVYg=; b=ycVaumwESIQe+zFzEZJUHrbeK65r4Z5k/3jN7fgVpcZS4QvrYlUG/nn/STPprq0q27 RFjRs1OSrPrFkhuCpFA5nDBaHHV86xL/oriT+/oBmctqAfe1tSocKKNMb86dMy+gl1B9 YRi9zn/dtVyvheBclQTp+++Cl/z/mHM4afJNyv27OHNgNVyFoduQ5MATk2yUuQpERvBJ 9KkyxhpN3xcXIrgQeNcrUSw4zl7Rc/v47RQ4DUVinpVnLnaa6+R4r9gKcH3T6dIX3zEL NobjDlfA5omZdizoE4755gGpoJ7zeeFZd1jOvaO8kEiqC+LQJ/znsHcJCh5F61gP49kZ XUmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V6kuiAPT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si20625617plc.403.2018.05.24.03.25.44; Thu, 24 May 2018 03:25:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V6kuiAPT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032000AbeEXKZL (ORCPT + 99 others); Thu, 24 May 2018 06:25:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:48468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031061AbeEXKCK (ORCPT ); Thu, 24 May 2018 06:02:10 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE18920891; Thu, 24 May 2018 10:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156130; bh=sgE+jDZ0TVC6HzSjVM1xODTuhALHuskC7vNJtefU1CM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V6kuiAPThpMJy3FjIQq7MSYXESxQ90VjjSPiA7VaU/89u/txhdDVBs82a+AIQExVj hhO0q12BnKAtR/8boaAwYFFJsJtNHyLbU3gOfoOOZtC3g7qR/AIl+ZawF4Opw3t/2b 5q0TDxLIEIqw+oPWQvahT4R3rsLdtnR8D/IvnHi0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Felipe Balbi , Sasha Levin Subject: [PATCH 4.16 075/161] usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS Date: Thu, 24 May 2018 11:38:20 +0200 Message-Id: <20180524093027.532468790@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lars-Peter Clausen [ Upstream commit 946ef68ad4e45aa048a5fb41ce8823ed29da866a ] Some UDC drivers (like the DWC3) expect that the response to a setup() request is queued from within the setup function itself so that it is available as soon as setup() has completed. Upon receiving a setup request the function fs driver creates an event that is made available to userspace. And only once userspace has acknowledged that event the response to the setup request is queued. So it violates the requirement of those UDC drivers and random failures can be observed. This is basically a race condition and if userspace is able to read the event and queue the response fast enough all is good. But if it is not, for example because other processes are currently scheduled to run, the USB host that sent the setup request will observe an error. To avoid this the gadget framework provides the USB_GADGET_DELAYED_STATUS return code. If a setup() callback returns this value the UDC driver is aware that response is not yet available and can uses the appropriate methods to handle this case. Since in the case of function fs the response will never be available when the setup() function returns make sure that this status code is used. This fixed random occasional failures that were previously observed on a DWC3 based system under high system load. Signed-off-by: Lars-Peter Clausen Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3238,7 +3238,7 @@ static int ffs_func_setup(struct usb_fun __ffs_event_add(ffs, FUNCTIONFS_SETUP); spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); - return 0; + return USB_GADGET_DELAYED_STATUS; } static bool ffs_func_req_match(struct usb_function *f,