Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2445121imm; Mon, 28 May 2018 08:12:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoP1YWEnAidK85zKFYVvydcZNn7IScyo02G1kL3NCroLuNo343CCHvFS1MMQjEYNch8XOEO X-Received: by 2002:a63:a557:: with SMTP id r23-v6mr10952038pgu.336.1527520368211; Mon, 28 May 2018 08:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527520368; cv=none; d=google.com; s=arc-20160816; b=oY3UteYcXzFrc0ky7t9wsBIgdSJM2N+ZpnmDYfISIQPtC4/U1uSqvk18P0dOaGH43+ HltHXYfow6iqFRXFyQsOQgxPMJqNPkT3Ek5lbxLDC9rx9pXSn81wM+oYu43/rJVBUag8 Z0D4gwp+wgk/0dO6VuwSCiFhif1o/lwndNe15mUikAw6tuow1ObqKB9xOoqbm2a3ZbQz 5xaXWQqLbRagRWuZU+3C0eRk1AX9gnHr89LUpHRP5rOAIymAnMwHn94oqgZDcUJnSJen V2YahgvzuGxRHuNrO6Hltcc3cmMt4RWAlF/Qmd02LaEPjyE27j8ohs3vbfSk9FsI2JtV UXUw== 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=tJ49FTACNPhcRA3386X5XQvxoBeV1lGlSiSE0z+DWBI=; b=Lje+FZQAP4CRwUnBeSUGfCpuyOR1XK9J4pDPJLOYvexu26WZ/FLs0gKiJk/uSSM+QL KPp/LuFzVJwWRutdjbpqnaGFnZkJN+g7ILn/RgVXZ6PnldTKGi+4L6bEl4rZA6wEJz0s jK7edkVErMIPM2oe1V0XSiG/qHdnrkAGAGpbigJ3B0s9QES32bMOzGEU9odlFqEgj7of rWR+UP6opipVInSRG6aXAayqWxd1mS82u8dUJrv+04+W7c/LPoS6/wkfZa186IZ4Javk kcZZI5m84O7NuaoXH53LyTrjLA2JOyZ/AI3t5i+KU+tVzeEY8YOLZoU/2TxoC6gUthqe GVBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jp1OhB55; 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 i4-v6si30247458plt.581.2018.05.28.08.12.33; Mon, 28 May 2018 08:12:48 -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=Jp1OhB55; 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 S1033722AbeE1KXt (ORCPT + 99 others); Mon, 28 May 2018 06:23:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:43076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033704AbeE1KXn (ORCPT ); Mon, 28 May 2018 06:23:43 -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 7847320883; Mon, 28 May 2018 10:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527503023; bh=w6mcDdvM2WP8RDtJy0nFHtWeXQ8S6aLplUQBWyLktwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jp1OhB55QCd9ysk7A83oMTfCkiiN5Pw1atBjigRkuLy94g5thQHryoQoU/MVqY5O7 z5gAKiSWGgyMahDcBhyBBC8kNphrwkTVlre/NYqe+Enf2KUB/sZTkrq7fqVYpMSv8O R8kHzCnDFdqAnInSiuJuEnvxRGB0MpWnJADlPqkQ= 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.4 214/268] usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS Date: Mon, 28 May 2018 12:03:08 +0200 Message-Id: <20180528100226.493260733@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@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.4-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 @@ -3033,7 +3033,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 void ffs_func_suspend(struct usb_function *f)