Message ID | 20230628222437.3188441-1-Frank.Li@nxp.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9254091vqr; Wed, 28 Jun 2023 15:44:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kbCuv+JckcgonGi0M8wD34V4G8A5n00m1ULrsI89gNXTh/r8roXuP7jU13JQffFo4Tor8 X-Received: by 2002:a05:6a00:4212:b0:675:8521:ddc7 with SMTP id cd18-20020a056a00421200b006758521ddc7mr12012843pfb.0.1687992264206; Wed, 28 Jun 2023 15:44:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687992264; cv=pass; d=google.com; s=arc-20160816; b=kRF8WDlV8qVrmxH9XDKeN0b+XdbXFkW3h4QIQiZuiFhN8w5JWYeRsRd2BFxxTUlSLX q7mFYE0xvbynIxSAO9AKJY8pqLOJTnOtj8mYReJ2UHaIBhXON3JAm1gfn/rNyiVHE+Xp Th13u8cRP36EbYWDyN+FbNhb2WLYI4dvAeBgFlcVSWW0Qyqbt9MEqEoGIfUjaVUydb3P NEVGtbW/56Jp4kMSEZduWi6XUpY3vt+DeeAnwUi+ICMHWRMxevzd+UrVcJJ61vdxmC9j 6YL0mKy/YTnibbEgOMPcrzF1l3OPqHa9gbVikObH3R5KEqJROvSOXImHJ5wrXD1V7qmR DuIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:to:from:dkim-signature; bh=k9MJqgXQBKH9p6GXj7nxHl/BRBNIsFl4yA15DxmnC7Q=; fh=/TMYo7VS9RGOhQpbi7DF/jrBW/8PbZv/kE9M1+91vkk=; b=Q5DGRyJ/n8ZnE6ZiOeNvEa1Mn9TebGUZcsNfksJh7T5R8hsg5/BlVqKuzHj7QYu6WX xXxxe3vopH3kNE9S+uWXEsbR1cXqO9H3wVX8HWFPypp05bsAMwfV+LJKmh/6WVRLCyRJ tn035s9qjE2pysHeue7/ZVCUdJPvuBeOpLwVo3s5MD/u6O3VzXxyUEiBA8nTjo9dnbbf LG6LJGOkPMKucAh71P1iL/tMObAZhfqrsADb8LUKdZpPPf2QwIZ+GX2jtZqg1qhLUMW1 riS0lEXWU57Wq9UmOZuuWvB+KiB2WKugVL2Y89dmv/TvmK7VuK7T+SpbiyixX2+SXMUH PGqQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b="EpYEd/az"; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cq15-20020a056a00330f00b00680098cc5f8si2251564pfb.84.2023.06.28.15.44.11; Wed, 28 Jun 2023 15:44:24 -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=@nxp.com header.s=selector2 header.b="EpYEd/az"; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231421AbjF1WZA (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Wed, 28 Jun 2023 18:25:00 -0400 Received: from mail-db5eur02on2071.outbound.protection.outlook.com ([40.107.249.71]:3265 "EHLO EUR02-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231300AbjF1WY6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 28 Jun 2023 18:24:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XpwnuLpMD0v3APyu5jzeBFW4z9wFlw1HXLusPrtL+u34Omhi3J7EF6cZISBmMVTt9yF/pFTDe8Q7N4ksIrgZhxo7H+Lb3p+tBseYCY4ChRDB+3jVrUkf3TDiNZQRBXFR/zyzttt6q4F/RbbWyHUG4ok4CdEdPEg5B4x0x8IO7opaLOIUeBm5JiElojw1ihQfHeknJhzqYQmPGePKqiC5Jf3twNjlucVTqE6toYC4B69Q/jfhFChe91WzX3MwoMuxr1O0+WlTor7XuFcfvjBABoRfBSo23O+o2Ad04HxfKQfbMwPUf9mVRdR7Uf4AkLVGXrlwjoyFXJkGIrvV6CIslg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k9MJqgXQBKH9p6GXj7nxHl/BRBNIsFl4yA15DxmnC7Q=; b=Eah04OFZXS7t+7SzgSyi/WNkELY/dKWywVJ8ryNQSSIth8+qtOqTsj4UHeB+W1O5maHiiP2TjjMDZV/XpeGH7IyXPeUf7ZzYz+KtMol6iG+Bj6aObvFh2HLVEv3Oe5WBg/M3M69g88wmfX4ssraj9Q3j3AMN9LX5eibDGc5tXN9rqcHcq8gbr30fnt0xMRHspaUi00tZ6NXXasDLxhdrMuvVcUNVmcjLEOFibcGbedb45a7ugHKYe/f+sJJvhdWb4Lp0cRnqOKGWNvJu3FKK9WP4oP4l4UO2DEQgKbfE4Qf647OTFcgHflRAO0IOl71L4mjo6fzhPSHBLimlYUrHHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k9MJqgXQBKH9p6GXj7nxHl/BRBNIsFl4yA15DxmnC7Q=; b=EpYEd/azGYEoOeOAT4yp3nB62n6XaiX44eAh3Q5j5cH3tTpPhXMUUsEb37lk1H0byptjb3D83Y5Ng+yg4bKLdAHo/QIpNxiwMCqKGS3a+U4KQXiBxCS8IUBLghCxmqn2rhDo/rvPV9wLiQrP33rBwDj6nLrjZbOYrJxcRdgetb0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by VI1PR04MB9978.eurprd04.prod.outlook.com (2603:10a6:800:1d7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Wed, 28 Jun 2023 22:24:54 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::4a2a:262e:415f:e41c]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::4a2a:262e:415f:e41c%7]) with mapi id 15.20.6521.026; Wed, 28 Jun 2023 22:24:54 +0000 From: Frank Li <Frank.Li@nxp.com> To: rogerq@kernel.org, r-gunasekaran@ti.com, imx@lists.linux.dev, jun.li@nxp.com, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Elson Roy Serrao <quic_eserrao@quicinc.com>, Thinh Nguyen <Thinh.Nguyen@synopsys.com>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, =?utf-8?b?SsOzIMOBZ2ls?= =?utf-8?b?YSBCaXRzY2g=?= <jgilab@gmail.com>, Prashanth K <quic_prashk@quicinc.com>, Peter Chen <peter.chen@kernel.org>, linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/1] usb: gadget: call usb_gadget_check_config() to verify UDC capability Date: Wed, 28 Jun 2023 18:24:36 -0400 Message-Id: <20230628222437.3188441-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR13CA0036.namprd13.prod.outlook.com (2603:10b6:a03:2c2::11) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|VI1PR04MB9978:EE_ X-MS-Office365-Filtering-Correlation-Id: 86813297-e0c0-4536-4c10-08db78267ee9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H0XUWOr+MXgUFfX0TvTs5FsOl3TUVevWSTFef5zZPsjL5fZZwruDitAA8iI3BOvbCVu1+sNHigCxtzmZyFGt+iB5bo/ltzWg0kw2snEeJOqhqZoHtbPX9OhJEsp0m+BtZpWK3pUMFUiPTTMP0JlqIDVGWkK7IirV/wrfLjVARgCYSiUjeLfUNL0mei0liELxNXob7MvIV0mwDE+X4tr/SLS9JQW4+FemQdvMRoN8G/K0+qg5iAxaQ+lvMbuDbc70R/SpHLIbPvhom3eij62HxWIKodLGG5oQlZFmSxAGI1S+4rtQ9IQxNNW+058b9SdMkbtqavF3c6132UnPGqJjjWoblVjws+TzHQkVPeE2au8F6dRA0azSuufPwyt/0HyeBKVHZVdkdabBb7R7juEJCWZLqT+K/x+EUwfKYnuh112J7OOkus2EEP5A6RA9wG5ajTZSUSLnErQ0xZ4izChknVOwbsBV73Q9VsK1gDnWyL6OgwBaTN/w06OqrCog7O3dpod/viq3PszIB0V4eJ5AxfHp1TV+DnOyCXDlisazjdNo974GNNFAt3oMsU8q4vqOWF3CmRDrK34jtHq1K8H7NdjHxsH0VYW5TmP7lRSQ6b3iypmbopRWsc8RRCyrfuYgSC3BASzqUctZhbNL9lo6RA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(136003)(39860400002)(366004)(396003)(451199021)(6512007)(26005)(2906002)(86362001)(6666004)(6486002)(52116002)(38100700002)(38350700002)(2616005)(921005)(186003)(110136005)(41300700001)(478600001)(36756003)(66946007)(66556008)(316002)(66476007)(1076003)(7416002)(6506007)(5660300002)(8936002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CjRP3YKvVtgHap+HKFnHf54MYC8YXKstCa8na02Kvl/g7OhiqKtgMhUawCUN1OtXG1yjNnvZfHt5IpM+C4hLH5XxotAkeNpWEHsU09zFB7ybMFjVvOctGfXsyoCkgIVjG5UIXuDg/7Y0s0MoWeJD+yAxhYD5k4Lq+NQ0+fEOkW3pjC5C0J2UNZ6Gz+gCK1nrW4wibXMrgfXD2QUD+nqPU4UgjROqxQd2/GBWTYZ+tzDhcYHx1A0RDVx+bUlmLi1e+6wgTABSk1EgHT9uX663nHIeBzgrSPoRLfqKBA8xaVY1Rby6akJ/29tTbSPf2Bzcb8V3N7KQVPWKiPT6JtC3xteQIPhvzWG4Nbk2ITHHKvJXfrPV3aCtNoNQUefKzoygMOG5EBB3g55Dr3l1uR/P3XllS1+uswT8IqVFFMrGVw1Q+qFbTN3RGf+qhCMoZTrP5nMPcesiianmdoh3f+aj4+npp8WdYksBPC13OpqcEkydo0mizvUUpQGE1aEydgeY8JX6l0LorrJo7FLXquGtON3I+LPA29PDwLAs+Nb6q1TWf9BPhWIt00nB+fHv83c/Tvqy/MQKUY0MAUFo6YlZacODh9vnI9NmlvwahHSrrL8JE0NpeafPhwegwtd2CMpQ8y1So5BH6SFp+LzyOuilpJyOS0xzY4baA5V+BkH6vU8KGzfxssqZRARhtnHTZuHBxeH9SNHlPNQSOikSrIjILTa8gQ72Z3UIQn0aXFPqWweBkA3EnK5+ip4Kq2BKFPo8htzuTdr9PupHoJFt3GBJyljfD1v5X+VYdyg4E8+mn2yRMVWtn3qIBQv77q7ta4ioevLpzYW6APGqbA5AdXwodKpp1T6V2hcuhUnT2spx5k+cqBJ3o9B0gRyjDucfaGBMLSXGlJYev9nDuuWPWelGkifLObEvXAU5UBjHdWc3INljsUmTkv9Q+NVY+hkXFJEv5M/W+f3+VydhUnZpTc3H2KtjSuRmNsRMWhVvOCJcuBxJc173kcuMF3KxMF/13JNwCtJc+AZLZAkcuUjtm06W4v6HmtxauWAoTyeuXQxxxJFE1FXs2WGBN/oluVv+hjApCccbi1hslXLNlqSg78x+eaTNO8vX+VMo5rYKQY/XkuU01wTqzq/tYQK7A2ybAzzi8YpnBqm7tuGpNYHv5nAau3I3L6P5ElRT35nkITM7W4FOI/Okcjc0cVO6pC3HN+xXjqCOBLGO7eqfTP4HcLoaY6nyFkaR8aOO8LxzjRg7PyhUEp35Bn3ti8qI1Pbj7gJi+9QgWu/+lPg7XOL/UIVpmjs2TvTmVEMPcBCUDeTRTtG/N7N6v7dOH9KZs83Wl2DRA22jugeAk42Zhn5frDV7WMkhYdg5FOs6PMrOPujtrf2VajQdf8Vj3bNpY53MddifJIXun7Jwom2E8I1WtKfu9QTNj8YVW7z5Z2ln8enbYwlw3GsFFRzgFWzJ+U43X5ZPURlsR+PQf1vgvvK31oUqTVZHJkN7yg4ZUKUi+i33VZABIznovo2oXa53nHUH6ZKgmRAFdJsQQGWFXsgyM5nSKObzWfc6QEhLYVUsO/56Vurp2of9sCSIqZO/H/KcEQMJ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86813297-e0c0-4536-4c10-08db78267ee9 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2023 22:24:53.9665 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wFZY3ZKtdaU2SuRmQSalrtmXFH5AqBaHJBUbS3BW65AtuecJfTmP0ghNXsWtdu7K7TdxxLQDIQ+YB/yRuB99LQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB9978 Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769988176004889064?= X-GMAIL-MSGID: =?utf-8?q?1769988176004889064?= |
Series |
[1/1] usb: gadget: call usb_gadget_check_config() to verify UDC capability
|
|
Commit Message
Frank Li
June 28, 2023, 10:24 p.m. UTC
The legacy gadget driver omitted calling usb_gadget_check_config()
to ensure that the USB device controller (UDC) has adequate resources,
including sufficient endpoint numbers and types, to support the given
configuration.
Previously, usb_add_config() was solely invoked by the legacy gadget
driver. Adds the necessary usb_gadget_check_config() after the bind()
operation to fix the issue.
Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")
Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/usb/gadget/composite.c | 4 ++++
1 file changed, 4 insertions(+)
Comments
On 29/06/2023 03:54, Frank Li wrote: > The legacy gadget driver omitted calling usb_gadget_check_config() > to ensure that the USB device controller (UDC) has adequate resources, > including sufficient endpoint numbers and types, to support the given > configuration. > > Previously, usb_add_config() was solely invoked by the legacy gadget > driver. Adds the necessary usb_gadget_check_config() after the bind() > operation to fix the issue. You have only fixed composite.c. Not all gadget drivers use composite.c so it will be still broken for them. Please also add default sane configuration in CDNS3 so it works even if usb_gadget_check_config() is not invoked. > > Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number") > Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/usb/gadget/composite.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c > index 1b3489149e5e..dd9b90481b4c 100644 > --- a/drivers/usb/gadget/composite.c > +++ b/drivers/usb/gadget/composite.c > @@ -1125,6 +1125,10 @@ int usb_add_config(struct usb_composite_dev *cdev, > goto done; > > status = bind(config); > + > + if (status == 0) > + status = usb_gadget_check_config(cdev->gadget); > + > if (status < 0) { > while (!list_empty(&config->functions)) { > struct usb_function *f;
> -----Original Message----- > From: Roger Quadros <rogerq@kernel.org> > Sent: Wednesday, June 28, 2023 10:23 PM > To: Frank Li <frank.li@nxp.com>; r-gunasekaran@ti.com; imx@lists.linux.dev; > Jun Li <jun.li@nxp.com>; Greg Kroah-Hartman > <gregkh@linuxfoundation.org>; Elson Roy Serrao > <quic_eserrao@quicinc.com>; Thinh Nguyen > <Thinh.Nguyen@synopsys.com>; Andy Shevchenko > <andriy.shevchenko@linux.intel.com>; Jó Ágila Bitsch <jgilab@gmail.com>; > Prashanth K <quic_prashk@quicinc.com>; Peter Chen > <peter.chen@kernel.org>; open list:USB SUBSYSTEM <linux- > usb@vger.kernel.org>; open list <linux-kernel@vger.kernel.org> > Subject: [EXT] Re: [PATCH 1/1] usb: gadget: call usb_gadget_check_config() > to verify UDC capability > > Caution: This is an external email. Please take care when clicking links or > opening attachments. When in doubt, report the message using the 'Report > this email' button > > > On 29/06/2023 03:54, Frank Li wrote: > > The legacy gadget driver omitted calling usb_gadget_check_config() > > to ensure that the USB device controller (UDC) has adequate resources, > > including sufficient endpoint numbers and types, to support the given > > configuration. > > > > Previously, usb_add_config() was solely invoked by the legacy gadget > > driver. Adds the necessary usb_gadget_check_config() after the bind() > > operation to fix the issue. > > You have only fixed composite.c. Not all gadget drivers use composite.c > so it will be still broken for them. > > Please also add default sane configuration in CDNS3 so it works even > if usb_gadget_check_config() is not invoked. Which one was not call usb_add_config()? DWC3 also use .check_config = dwc3_gadget_check_config, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/dwc3/gadget.c I think it is not correct by assume UDC can support specific config at gadget function driver. Add default value of CDNS3 actually hidden potential problem. I don't suggest it before fixed hidden potential problem. Frank > > > > > Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to > composite EP number") > > Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > --- > > drivers/usb/gadget/composite.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/drivers/usb/gadget/composite.c > b/drivers/usb/gadget/composite.c > > index 1b3489149e5e..dd9b90481b4c 100644 > > --- a/drivers/usb/gadget/composite.c > > +++ b/drivers/usb/gadget/composite.c > > @@ -1125,6 +1125,10 @@ int usb_add_config(struct usb_composite_dev > *cdev, > > goto done; > > > > status = bind(config); > > + > > + if (status == 0) > > + status = usb_gadget_check_config(cdev->gadget); > > + > > if (status < 0) { > > while (!list_empty(&config->functions)) { > > struct usb_function *f; > > -- > cheers, > -roger
On 6/29/23 3:54 AM, Frank Li wrote: > The legacy gadget driver omitted calling usb_gadget_check_config() > to ensure that the USB device controller (UDC) has adequate resources, > including sufficient endpoint numbers and types, to support the given > configuration. > > Previously, usb_add_config() was solely invoked by the legacy gadget > driver. Adds the necessary usb_gadget_check_config() after the bind() > operation to fix the issue. > > Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number") > Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/usb/gadget/composite.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c > index 1b3489149e5e..dd9b90481b4c 100644 > --- a/drivers/usb/gadget/composite.c > +++ b/drivers/usb/gadget/composite.c > @@ -1125,6 +1125,10 @@ int usb_add_config(struct usb_composite_dev *cdev, > goto done; > > status = bind(config); > + > + if (status == 0) > + status = usb_gadget_check_config(cdev->gadget); This will work for legacy gadgets that support only one configurations. Take for example g_ether. It has two configurations when RNDIS is enabled. And usb_add_config() is invoked for each configuration. cdns3_gadget_check_config() calculates the total IN end-points based on the ep->claimed flag. list_for_each_entry(ep, &gadget->ep_list, ep_list) { if (ep->claimed && (ep->address & USB_DIR_IN)) n_in++; } This ep->claimed flag is later cleared by usb_ep_autoconfig_reset() which is invoked in usb_add_config(). So for multi-configurations, actual total in end points is not taken into consideration thus resulting in incorrect fifo size allocation/check. g_ffs is another gadget which has multiple configurations. > + > if (status < 0) { > while (!list_empty(&config->functions)) { > struct usb_function *f;
> -----Original Message----- > From: Ravi Gunasekaran <r-gunasekaran@ti.com> > Sent: Thursday, June 29, 2023 12:11 AM > To: Frank Li <frank.li@nxp.com>; rogerq@kernel.org; imx@lists.linux.dev; > Jun Li <jun.li@nxp.com>; Greg Kroah-Hartman > <gregkh@linuxfoundation.org>; Elson Roy Serrao > <quic_eserrao@quicinc.com>; Thinh Nguyen > <Thinh.Nguyen@synopsys.com>; Andy Shevchenko > <andriy.shevchenko@linux.intel.com>; Jó Ágila Bitsch <jgilab@gmail.com>; > Prashanth K <quic_prashk@quicinc.com>; Peter Chen > <peter.chen@kernel.org>; open list:USB SUBSYSTEM <linux- > usb@vger.kernel.org>; open list <linux-kernel@vger.kernel.org> > Subject: [EXT] Re: [PATCH 1/1] usb: gadget: call usb_gadget_check_config() > to verify UDC capability > > Caution: This is an external email. Please take care when clicking links or > opening attachments. When in doubt, report the message using the 'Report > this email' button > > > On 6/29/23 3:54 AM, Frank Li wrote: > > The legacy gadget driver omitted calling usb_gadget_check_config() > > to ensure that the USB device controller (UDC) has adequate resources, > > including sufficient endpoint numbers and types, to support the given > > configuration. > > > > Previously, usb_add_config() was solely invoked by the legacy gadget > > driver. Adds the necessary usb_gadget_check_config() after the bind() > > operation to fix the issue. > > > > Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to > composite EP number") > > Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > --- > > drivers/usb/gadget/composite.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/drivers/usb/gadget/composite.c > b/drivers/usb/gadget/composite.c > > index 1b3489149e5e..dd9b90481b4c 100644 > > --- a/drivers/usb/gadget/composite.c > > +++ b/drivers/usb/gadget/composite.c > > @@ -1125,6 +1125,10 @@ int usb_add_config(struct usb_composite_dev > *cdev, > > goto done; > > > > status = bind(config); > > + > > + if (status == 0) > > + status = usb_gadget_check_config(cdev->gadget); > > This will work for legacy gadgets that support only one configurations. > Take for example g_ether. It has two configurations when RNDIS is enabled. > And usb_add_config() is invoked for each configuration. > > cdns3_gadget_check_config() calculates the total IN end-points based on the > ep->claimed flag. > > list_for_each_entry(ep, &gadget->ep_list, ep_list) { > if (ep->claimed && (ep->address & USB_DIR_IN)) > n_in++; > } > > This ep->claimed flag is later cleared by usb_ep_autoconfig_reset() which is > invoked in usb_add_config(). So for multi-configurations, actual total in end > points > is not taken into consideration thus resulting in incorrect fifo size > allocation/check. > > g_ffs is another gadget which has multiple configurations. Actually it is another problem that I am trying to figure out. Configfs should have similar Problem. We never test multi config case in configfs also. Generally, composite device only have multi interfaces. cdns3_gadget_match_ep wrong cache all endpoints for all configs, but actually only one config can be active. Frank > > > > + > > if (status < 0) { > > while (!list_empty(&config->functions)) { > > struct usb_function *f; > > -- > Regards, > Ravi
On 29/06/2023 06:40, Frank Li wrote: > > >> -----Original Message----- >> From: Roger Quadros <rogerq@kernel.org> >> Sent: Wednesday, June 28, 2023 10:23 PM >> To: Frank Li <frank.li@nxp.com>; r-gunasekaran@ti.com; imx@lists.linux.dev; >> Jun Li <jun.li@nxp.com>; Greg Kroah-Hartman >> <gregkh@linuxfoundation.org>; Elson Roy Serrao >> <quic_eserrao@quicinc.com>; Thinh Nguyen >> <Thinh.Nguyen@synopsys.com>; Andy Shevchenko >> <andriy.shevchenko@linux.intel.com>; Jó Ágila Bitsch <jgilab@gmail.com>; >> Prashanth K <quic_prashk@quicinc.com>; Peter Chen >> <peter.chen@kernel.org>; open list:USB SUBSYSTEM <linux- >> usb@vger.kernel.org>; open list <linux-kernel@vger.kernel.org> >> Subject: [EXT] Re: [PATCH 1/1] usb: gadget: call usb_gadget_check_config() >> to verify UDC capability >> >> Caution: This is an external email. Please take care when clicking links or >> opening attachments. When in doubt, report the message using the 'Report >> this email' button >> >> >> On 29/06/2023 03:54, Frank Li wrote: >>> The legacy gadget driver omitted calling usb_gadget_check_config() >>> to ensure that the USB device controller (UDC) has adequate resources, >>> including sufficient endpoint numbers and types, to support the given >>> configuration. >>> >>> Previously, usb_add_config() was solely invoked by the legacy gadget >>> driver. Adds the necessary usb_gadget_check_config() after the bind() >>> operation to fix the issue. >> >> You have only fixed composite.c. Not all gadget drivers use composite.c >> so it will be still broken for them. >> >> Please also add default sane configuration in CDNS3 so it works even >> if usb_gadget_check_config() is not invoked. > > Which one was not call usb_add_config()? > DWC3 also use > .check_config = dwc3_gadget_check_config, > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/dwc3/gadget.c I meant gadget drivers not UDC drivers. e.g. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/gadget/legacy/dbgp.c > > I think it is not correct by assume UDC can support specific config > at gadget function driver. > Add default value of CDNS3 actually hidden potential problem. > > I don't suggest it before fixed hidden potential problem. > > Frank > >> >>> >>> Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to >> composite EP number") >>> Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com> >>> Signed-off-by: Frank Li <Frank.Li@nxp.com> >>> --- >>> drivers/usb/gadget/composite.c | 4 ++++ >>> 1 file changed, 4 insertions(+) >>> >>> diff --git a/drivers/usb/gadget/composite.c >> b/drivers/usb/gadget/composite.c >>> index 1b3489149e5e..dd9b90481b4c 100644 >>> --- a/drivers/usb/gadget/composite.c >>> +++ b/drivers/usb/gadget/composite.c >>> @@ -1125,6 +1125,10 @@ int usb_add_config(struct usb_composite_dev >> *cdev, >>> goto done; >>> >>> status = bind(config); >>> + >>> + if (status == 0) >>> + status = usb_gadget_check_config(cdev->gadget); >>> + >>> if (status < 0) { >>> while (!list_empty(&config->functions)) { >>> struct usb_function *f; >> >> -- >> cheers, >> -roger
On Fri, Jun 30, 2023 at 10:43:14PM +0300, Roger Quadros wrote: > > > > .check_config = dwc3_gadget_check_config, > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/dwc3/gadget.c > > I meant gadget drivers not UDC drivers. > > e.g. > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/gadget/legacy/dbgp.c > This is for EHCI host controller debug port, specially implement simple tty gadget devices. Generally used for PC. This driver suppose will not use UDC at all.
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 1b3489149e5e..dd9b90481b4c 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1125,6 +1125,10 @@ int usb_add_config(struct usb_composite_dev *cdev, goto done; status = bind(config); + + if (status == 0) + status = usb_gadget_check_config(cdev->gadget); + if (status < 0) { while (!list_empty(&config->functions)) { struct usb_function *f;