From patchwork Mon Aug 28 15:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 137052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp3463068vqm; Mon, 28 Aug 2023 10:03:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTFzA8GyMzISNkPrXJqyTLK882PN8SqFA+mEzGaz9nEGERfbENVTuBBdvuVKRPNBGl5jdr X-Received: by 2002:a50:fc10:0:b0:523:c36e:ec8b with SMTP id i16-20020a50fc10000000b00523c36eec8bmr142603edr.9.1693242205711; Mon, 28 Aug 2023 10:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693242205; cv=none; d=google.com; s=arc-20160816; b=WnCjRfm5rZ7Nttw0ACXuxM071hG6StzJQjcLvGZi1BUiRByV1wYNCeBKI45/V9+hCO Jpzd/KwfZh/XP4RGobJFNGHomLUu9hwHYizGbKUJJ7qdDAfT5Iu4iVnnGWVBBFPw0M9l XSLUi0AkyVLBzpMZkPi+Hg7t5cnA3eNCfRarz8Zmach6O4drN/OPyhgaLLzYejZ89DYC yVv1AbQoNwqxATlwK+wOf1gnylp8Vk7GcHinbb8WoVI6EBGlY2QxCgKGm09+javNnnh8 q0IigtL595j0CWiqIfoVYDFCoYVCF6BMdibizbAs5ZlSW8sQ5QILZvkfJUvqOG/kwpsd 5LFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AF/k9KMisM9L/zADuvNUFCBoEX8c5c0K7cCwf6wH2B4=; fh=MAA75nCRszWddAQ+RbHBX0YbyV/1cC0P3K7GQcCsOLs=; b=0ekQJ0V7AUNJUqACgzfS9aiwdl2Bdbz1jn/nTvIUgc8OCje5deHqPgT/l2AvwErDmE W7Qc+GL9woRODJb5vjMREA/dhxlTTOxkavKuHcGOZqZBVWqeKJOtcPA++0Fc40wBjsnb wdAznko4qvUqSdn1N6zOc92VFxCL7oaOIZlhdY617qfJkPdrkvE8HQnDQDFvdlbjYj/S nGB6TqUFuyS0aQ13e2n0NZW2ijIpckcTZrC62aX0J9UZN2N8Ei+JvPcMENrisSaAs+2c vjZji7dn55QESOuAsqz9Q12Z8ECGgdQM//sw7oLBX9T93nHxj2GaPKBCpYySHqdFpdM+ 5WzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=YM9IegZT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020aa7da09000000b0052888f9cdbdsi4515766eds.326.2023.08.28.10.02.33; Mon, 28 Aug 2023 10:03:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=YM9IegZT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbjH1PvR (ORCPT + 99 others); Mon, 28 Aug 2023 11:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232537AbjH1Puq (ORCPT ); Mon, 28 Aug 2023 11:50:46 -0400 Received: from out-247.mta0.migadu.com (out-247.mta0.migadu.com [91.218.175.247]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED85C188 for ; Mon, 28 Aug 2023 08:50:41 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693237388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AF/k9KMisM9L/zADuvNUFCBoEX8c5c0K7cCwf6wH2B4=; b=YM9IegZT32pmaY9uupjiCI7Sa/1GKIP4EKZdVgx5L6JJIzP2HNyeKyCr2iV/01mc7Wk/uJ TtC3on7kWFIYuRLA5KNukwHvzrjcEj1Tj8svdcUjBcgSvou8FVNJXVsPijKdRZeude4Iwv 6P5SSpBywmib77oA+irOh5dqusPqk7w= From: andrey.konovalov@linux.dev To: Greg Kroah-Hartman Cc: Andrey Konovalov , Alan Stern , Felipe Balbi , Thinh Nguyen , Pawel Laszczak , Chunfeng Yun , Minas Harutyunyan , Justin Chen , Al Cooper , Herve Codina , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] usb: gadgetfs: return USB_GADGET_DELAYED_STATUS from setup() Date: Mon, 28 Aug 2023 17:43:04 +0200 Message-Id: In-Reply-To: <7f0ee06c68c7241c844cd50f8565fdd5ead79b1b.1693237258.git.andreyknvl@gmail.com> References: <7f0ee06c68c7241c844cd50f8565fdd5ead79b1b.1693237258.git.andreyknvl@gmail.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775493138941162705 X-GMAIL-MSGID: 1775493138941162705 From: Andrey Konovalov Return USB_GADGET_DELAYED_STATUS from the setup() callback for 0-length transfers as a workaround to stop some UDC drivers (e.g. dwc3) from automatically proceeding with the status stage. This workaround should be removed once all UDC drivers are fixed to always delay the status stage until a response is queued to EP0. Reviewed-by: Alan Stern Signed-off-by: Andrey Konovalov --- Changes v1->v2: - Added comment for composite.h include as suggested by Alan. - Moved undefs next to composite.h include as suggested by Alan. --- drivers/usb/gadget/legacy/inode.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c index 28249d0bf062..e71cd591cda1 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -31,6 +31,12 @@ #include #include +#include /* for USB_GADGET_DELAYED_STATUS */ + +/* Undef helpers from linux/usb/composite.h as gadgetfs redefines them */ +#undef DBG +#undef ERROR +#undef INFO /* @@ -1511,7 +1517,16 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) event->u.setup = *ctrl; ep0_readable (dev); spin_unlock (&dev->lock); - return 0; + /* + * Return USB_GADGET_DELAYED_STATUS as a workaround to + * stop some UDC drivers (e.g. dwc3) from automatically + * proceeding with the status stage for 0-length + * transfers. + * Should be removed once all UDC drivers are fixed to + * always delay the status stage until a response is + * queued to EP0. + */ + return w_length == 0 ? USB_GADGET_DELAYED_STATUS : 0; } }