Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1991052imm; Thu, 24 May 2018 04:08:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoRzKk+nK/2F9v22sTa5TymD8H2arwBQ74o5+t4p/UbeswwwexQ9mZp4xf6gVtdDdLJrxmg X-Received: by 2002:a65:66d7:: with SMTP id c23-v6mr5501376pgw.76.1527160129811; Thu, 24 May 2018 04:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527160129; cv=none; d=google.com; s=arc-20160816; b=GLfESlqjuhYM5uxIkq55YPaudunydydkcJen4irP59e0EOE6rvmivnb7iEzzxC1glL SciNQyEzwX/QZSIh1qlJ3ft1VtXL8YVgDS2dRfeD/+cwE31kxlMVdbtDVJkrUGJ8a+PQ B2vMWqL4Gr+HBkyrwHQaulFmqrgeswNBjl2T25K00AlAwrXgg6NguaE+jZ5fqUL+1pWt IJIF1VNH5n5NDieM8pTpbAzI9L9ZHKmGPjZv7tMSd7Irt4c1coIaEm2IVjc/tZp+YAzU cZ5AXf+2pb0i8gr+J9vwLHcpPeSqeUpxKFmHC+nGmazFzhhiwdFYYm4B2heghj95hmu8 UwVg== 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=+uol2akEooR1lrN+vm1jRTwjCy4jZBY7j0sluJCfDGs=; b=0SKeM7D7COsqThv+BFo/iiBcCVIzwtj8PZKblE3dxaVTueB6GnMOISVXgxfk2CcaLC DwXOswonNNdYH2G4xlTpJVI1lnGUy21ykHOirv7ljJthSgNkaF5SCvNxbb1vVmly7LKt q4u6IvJSLyEQvXzvE095QthLSikm1Rp3FSwlTX4nC79AK0QAkykTFKW0ched2NpWJLsK Lg8njJSdxorgOzClZQbIqLFSEWe+v055KhXX1HcPgH+An52GMl0bA3ttmKwjI8/f8rmN Sz9RTTNEd+PZkSwz3tSElEdcA/MpE0KZHP6rjJH5dSekYpds/P2Sbn6+bz2tcXLdv3Kp MaEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XxlCxafw; 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 e125-v6si20952377pfg.112.2018.05.24.04.08.35; Thu, 24 May 2018 04:08:49 -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=XxlCxafw; 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 S968232AbeEXJys (ORCPT + 99 others); Thu, 24 May 2018 05:54:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:34816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968213AbeEXJyk (ORCPT ); Thu, 24 May 2018 05:54:40 -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 85AE820891; Thu, 24 May 2018 09:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155680; bh=2NpikMenBBXJ8GWLMyXTUe6HTS3Mzb/w5wDDhD/3tHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XxlCxafw1WvT03TNeJyVULvouBMvIZwpX30nKz0zsoKKHk7G7zXL27T/okWt+aWQ4 shWhbEsqH/C4yKZ4/9cVmhhZjuvo9XEoYP3V3DuqpL+vSketZbssg7BzR1c/Se28Oj 2rHMfnZwHviRoX+vSvkh//z+gkPLyC06gsaJ3QQE= 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.14 076/165] usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS Date: Thu, 24 May 2018 11:38:02 +0200 Message-Id: <20180524093625.099127926@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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.14-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 @@ -3239,7 +3239,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,