Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2025863imm; Thu, 24 May 2018 04:44:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp2PuFj+id8c+VVS2SO5QlFmwf0gmZmqKZ5vjA5qOeklcH1fjvxvhx5cFVPexCzMPM230e4 X-Received: by 2002:a17:902:bd93:: with SMTP id q19-v6mr4524633pls.231.1527162253442; Thu, 24 May 2018 04:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527162253; cv=none; d=google.com; s=arc-20160816; b=RIVtBgJYLGqNy8QOFSdBcCU9/Q3wTPuAPXxefss/FPQtuvDW6RLnE0fCfE347t2u4V 0chpNte7h6b/xY3OmgUNSsOfJ8h8jnGbW7fLwI0mhdDlZvPH3Zbc3OTC/amrRWVRNYzo 9frbhZH0UlTUl4LmWFgm16AHKLysrD6J2hSVdw6v25d8JZkPpYWeZeiUfl5Kzk3Jzx5c W8EU6v0oQkBqVCeyMHj2nVsvBGLAxRVwS2qwQDWPL7RbU2s6AcHFEYIPyfZN2AWcYulo A0aSu5Iun0RkHMnYIufNsGf1Nao7mzPoFdw1JTqx7iGNMnfa7Xr70JoDiqxAVZx6cvzC OIEw== 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=VUqJEGJxozgJ2qCyNrgFwLliKWfswn183I5LyIjXnjI=; b=ia/IL5s5paaCeCFX+BCMBOD6mT0N1Gmtm2kSsHMvgBK22KexJwuaufQT5AgYDiIKIL FKJWSQ51YLwj4x5MsdbQ9y9u/dtNwYY2CZFFVL2MSVT65Pbc+BlWQSEray7aj6BH7aTJ s+L8eBSENl+7s845i6tMoWRHm0GfGSYlz+x5mkDUjaIoHwI5t473/yVaJaUt1bxFHS2V xG1mgbHTt5qDgxJAoCu2VWMmQoGF21SgvQqS0uHn7tsAZA4l+D8KTu8pomXmqrg+/jsH nxx6mtfypNUIMJaZuBVwLZIqoVb+WEQ8a223TCmGaSrb6elfTxWy+JnFRnNeAo80fdE/ odEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=remQvxvZ; 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 g8-v6si20738214plo.245.2018.05.24.04.43.58; Thu, 24 May 2018 04:44:13 -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=remQvxvZ; 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 S967386AbeEXLmF (ORCPT + 99 others); Thu, 24 May 2018 07:42:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:33844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967232AbeEXJsc (ORCPT ); Thu, 24 May 2018 05:48:32 -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 7D65420847; Thu, 24 May 2018 09:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155312; bh=j0RDuyhfKFXXrepZe8NmqcxpSs/8wHId0SFhuGAZCSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=remQvxvZXMGzTeiQwXuXt2H/pF3h59zGB2GIlN0C5F32PgqBAElfeYkK6MCRS4Wrp F2CYMp3qxC2LGEZT1Xc5vIc45FmFRIx9ZhIqDQOqOgnElNy7xFXs5Jb5tQZofLuK3W oLKWAZ0AhYCwXrmYl7rW5hHb0G1PQgZBtHZllSuk= 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.9 41/96] usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS Date: Thu, 24 May 2018 11:38:24 +0200 Message-Id: <20180524093607.887097559@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@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.9-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,