Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2504675imm; Mon, 28 May 2018 09:19:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoCltrapyrxO2Izya+WG5bEUT1kuIBqfJS3uHCgRtpOHfT3v109q8vgNmET69HPVaymWQzS X-Received: by 2002:a17:902:868b:: with SMTP id g11-v6mr13971480plo.305.1527524380296; Mon, 28 May 2018 09:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527524380; cv=none; d=google.com; s=arc-20160816; b=OfihWR1jn2WlqdaCnRjKLxrketI54kd0Fv8DKSipHJZqLoDIWyUEOvJ6f4PF+7L9P8 sXsipogNcu0QFyWsxDfQstozOJtcV4qToFw84LYdHlYPxg8o8yBJ3WVLlTJTQl+pDUZu FUyhpmQEVXEIsh92dDHztGPfe4IGUYJVfZDKt7gl7d2Bykh3OFC3ev1S5sCAuQvaKIfa Uf5Jan8EtgagMoCJ2cN5xxiwyQjZ1DNkH9Q+C2VCn8Y1ZYfkqbtTFAKGizzXYVnVLfTZ oKzxKLk67ZnoW3ejxcZNha7wxeNK+iIVm/hMz3DyuNCFlPDecTgTmnt8LDDuPAeFiVKL I1zg== 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=bDIOR4sxsIc6zihKMOPHQsC/yl1TVDeWyiZJd7+/2C4=; b=BOAj2+DLNwHB55Vfwt9g6+udCwCypTFVUkX+pUizx6PEqGOPJieFuSy7KmBmXgKFyf NEL3t7V17HXcBnpQHat3OcVQJT/SaHAJAiovjBENg1mc+Nv6KF/cJCuUHPTyVmRxJpYd z9pwkteF1K+F4SHwc+u9PCvO/dJLQbPW6G7TFqOT3l4qetXg276MM+6lGfqDDsqjz8iW 5kTbPp3HmvQ01BDqECo7mEPyud8TVrwe9K9FeaiYNvmG/FSv1Q1PWh2x1UMij1v+mtZd daWyLDKx/4KmC2jYU5JdSEdxAzY0lUS0676NE4L21r51Bq9MxtFfC1Rivxn9vnCQz7Sp bItg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g7AMrzgl; 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 x32-v6si29844162pld.435.2018.05.28.09.19.25; Mon, 28 May 2018 09:19:40 -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=g7AMrzgl; 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 S939961AbeE1QSw (ORCPT + 99 others); Mon, 28 May 2018 12:18:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:60468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936724AbeE1KMU (ORCPT ); Mon, 28 May 2018 06:12:20 -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 BBBCB208A2; Mon, 28 May 2018 10:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502340; bh=cuxMmzMzULlSzIpUJEb6S4SPEqENItQVh9LYTcKpQos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7AMrzgloDnNujq0HyQnsa4UYNAp7Yx8LvSd3ZLrXFaiOXRg7aE6/WnPyX5h/+q6Y 9HvQp7HMBv6cBxmNNj8dag3Of77AiedpqAhSlo9Du4JQyx2CsfyCDSkpPQhaZDFRJv rZO6CodFAnZClUJyaJ/vEndVk9+eRB+MIu7IVmLI= 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 3.18 151/185] usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS Date: Mon, 28 May 2018 12:03:12 +0200 Message-Id: <20180528100109.698484447@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@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 3.18-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 @@ -2987,7 +2987,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)