Message ID | 20221213220354.628013-1-Frank.Li@nxp.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp387729wrn; Tue, 13 Dec 2022 14:10:04 -0800 (PST) X-Received: by 2002:a05:6a21:3d0a:b0:ac:6cff:c3b9 with SMTP id bi10-20020a056a213d0a00b000ac6cffc3b9mr29063905pzc.42.1670969164955; Tue, 13 Dec 2022 14:06:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ue/9/pKTFPOTzXylRjJvfcSIDjagIfd6v0oZJzylN4Ru4HgY0c2wjOY7cWtBF9v3N38Yq X-Received: by 2002:a05:6a21:3d0a:b0:ac:6cff:c3b9 with SMTP id bi10-20020a056a213d0a00b000ac6cffc3b9mr29063746pzc.42.1670969163346; Tue, 13 Dec 2022 14:06:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1670969163; cv=pass; d=google.com; s=arc-20160816; b=O2MNSv+hFZH6EhLK9V2TiTiEv8IkRBUNBjEvOmf7r7MOF5gsOLYBPIxa+HB4t/H5Ol NCh3UlabJrK3Al5WZNMTWtqIWZS1HNranZ4qTVA+1x5Y30kBvwqmogPc+CUQBh+DS1Fu UIB6mXUeSThBVdpQrhpDIdyDcJnkQUhz/PYF2danNqeBHo04RLqHqpUL2XY+zb87YDk3 7GV+U+LrNgQ8rKmlvndx71bnp9IsN/EMpF7tz0qU3mi+UiKU78gCxWd7I0Qv1cSDTog3 zixEdb9CBSJAlW9m28TA7Tuy6ZodtnJozNpe2CbX15mhuM0lHFhwKDj4Xj0wMM5IXjDL hLtw== 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:cc:to:from:dkim-signature; bh=F6g5s/9eB0zMdHNRaRE0Nwl5TXFcNOlmIsalRklVRFE=; b=huFdEzYJO5dAAE9UXllKTKtBP+4A0G+urNIr5EdqDsyBekKkrq4j/Q/sSuK1/F+zeY /fUhD6rS0cfJeBvdhzyLkKwYOZtvLVjZOeK+ZBiN2ODCcNTR9o9NghgRap9/Tn5A5dsp nAcEIwieVzkQIkna+GF1Szf9aNd/OjB4xzdtrjJe6nJS3LWKmj82sbbpTwi7rEYJeiwp h80DqS4BMUvcuoZp5QR7HSK5vuuyx0q38IeuDly0j//vws7Vmlt/VBaBtcTsamWLcyji EJgOO1DP1o5QJp4Q51H3RnOJJoutKjYj3AUAefbLmTWI+UJuD5vbdzs/JF/tVMWSgHIo Jfjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=ZxsQqx85; 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 s186-20020a6377c3000000b0047857ac64aesi13255902pgc.352.2022.12.13.14.05.01; Tue, 13 Dec 2022 14:06:03 -0800 (PST) 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=ZxsQqx85; 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 S236426AbiLMWEX (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Tue, 13 Dec 2022 17:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236882AbiLMWEV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 13 Dec 2022 17:04:21 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2073.outbound.protection.outlook.com [40.107.7.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B245E98; Tue, 13 Dec 2022 14:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X6nO+7xvhgPS8AuMxNpC6g8l5pjStAb9FCVrjiJCV6Qolw5367fs5OZRSaXvPU8AGmF3w/Nm9/cBOi4PY7dCZWF2MmoGD8/RHKi7aF0vWW06fxnWKL9yVlM5OqBWmka/skzubUaBxoQ0pVmZIHIdRWAXJjzNB/WBMqNC1AvgbzcAfLQHCZMlK2jtLwR2lDX+WEnNz+FglOiUcZLocodR95ConVOrml6ijKLdIVNWT1VsLms/9BiKvvEnicWW/q0XoY5x9VW4veOV0seLz/Ln8wR+D/S+mXGnv5SjHt1l9N3HFxcz2PrPUVhnNWEAOrU5hJjUJuXzkQmoFrKPkaeOuQ== 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=F6g5s/9eB0zMdHNRaRE0Nwl5TXFcNOlmIsalRklVRFE=; b=gXbySAHhYx3AWtP963qzKeWAp6fM0MPU7Gkf9fdJeIvSm+T7mQkqq5OZGqzi8shPSo2vu7Lq4MznYxgV5NnGnBQu6qDhxv9fc+VrlXsCZbAeQYruwvyrWvaYHP4EDcSGExf0raN6eqf4lqrvbgHTPiGjlxAXsrayC/LsvvcIpK/S8AsXwflaLE4+3MbJflmjV+yxBHLzZXtv1Klf6XJDm7vJP5EJNARWDDieiW5sYG99xjO4KKyE62v0Gp3LUEj49hwXL9nlrMQMQXp0rWtRiB0iwjOiWKb9dd9UBRvEUo6ghS/WQTHS2VF6dRLR+0ZLsjBCtxDh5lGR3UjUe3iwog== 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=F6g5s/9eB0zMdHNRaRE0Nwl5TXFcNOlmIsalRklVRFE=; b=ZxsQqx854cQesQYRXRqI07BpQHy9LY8M7GMe0ZZMug45mhWQERb9oXNQo5uhYH4LGo5PEIouQl4AlLXf9HvtojXltCYYNb+evV/+jh6Yej5OiWR7nu/kyCMiHQ4PLG8QDpYQaBLN/Zw9qyshd57O/kzhZnqNNDcFzKsuQhqSG4U= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from HE1PR0401MB2331.eurprd04.prod.outlook.com (2603:10a6:3:24::22) by DB8PR04MB7196.eurprd04.prod.outlook.com (2603:10a6:10:123::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10; Tue, 13 Dec 2022 22:04:17 +0000 Received: from HE1PR0401MB2331.eurprd04.prod.outlook.com ([fe80::203a:e5da:a4a:7663]) by HE1PR0401MB2331.eurprd04.prod.outlook.com ([fe80::203a:e5da:a4a:7663%12]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 22:04:16 +0000 From: Frank Li <Frank.Li@nxp.com> To: frank.li@nxp.com Cc: balbi@kernel.org, gregkh@linuxfoundation.org, imx@lists.linux.dev, linhaoguo86@gmail.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, stern@rowland.harvard.edu Subject: [PATCH v2 1/1] usb: gadget: Assign an unique name for each configfs driver Date: Tue, 13 Dec 2022 17:03:54 -0500 Message-Id: <20221213220354.628013-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BY5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:a03:1f4::45) To HE1PR0401MB2331.eurprd04.prod.outlook.com (2603:10a6:3:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0401MB2331:EE_|DB8PR04MB7196:EE_ X-MS-Office365-Filtering-Correlation-Id: e0d2ec48-80f8-4898-5ea5-08dadd55f93e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QGjmxQ8edHxucuaYnuZJhagmvKb9OjyUw7HQtHAnMwz10beCujn8QsxpyhAY++XUGxgaScHiuOqsEat87kQFXLfRnYaMt0vpoyqgs1zVlXdXx72NTg8NEQNh4Bu3kvHIooXVGMdQlroDUnSN4EtDqIN317ALKR/14X0gM6SYQElO9e+FxrXmGAD1m7iHiqGQSWL2rZScZN8SAHhIEyMYn80/wasMtMbEUmUgtZphCUBy9/IXdtDoAZfCbg/MhKeXcRUskYxHjMmKjvhW0GR5VwZI9nhiEXLk+vaqr7tCZP1l3ij0YwJNFJmA0vLHuxWdbtBHANRMOY3mKPZcxmNxXbOiCExmhUYXYJVHwMyrqp8wicq9f0TRWK8m7FVOyAKXgdnP70rttCeAvy8dLCnhEVC717RPqrtAZKkZllBK7IZdf7ajN5KSfFw/gbxFuMEqbwDWdWDMg2MZrc6Vj8+wwDPZm8aRI2AG/XZnf4UdfdJsXz3MfWZmSEmSAlljRSRokNjvctom7S+SKmVQtnqIHnklPWbcUKJl8kDgMpz8G75beFAZHbU947N6T0JOonNUkceEBjuzeMMYcAazbVeyPj7RXsJPGme19dT/jLEXYFjc+DdNXO9AY7cD0f0osfsH6hCJmruB+EsSHh2bz74ePeTIq8w8911HrBeGF1ligN4lWCcnF+gFYQUyAtY8TAsr15RfQ0FvXJSd8V6Y5ellv4HhQ4RC4+cy2fjNFw8NJJ0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0401MB2331.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(136003)(346002)(376002)(366004)(451199015)(8936002)(5660300002)(37006003)(316002)(66556008)(8676002)(36756003)(66946007)(1076003)(41300700001)(66476007)(2616005)(4326008)(38100700002)(38350700002)(86362001)(83380400001)(2906002)(186003)(34206002)(6512007)(26005)(6486002)(966005)(52116002)(6506007)(478600001)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zwy026jCp6NS4iTTULB5c592+syYTCpSJMuzrqfzP1Sb2XHIwvWkRSqUtYh618oWEFNOXhbJ6CbTbaPkGxFxBcn/s8PVbx/ZF6knzy3sPgSrHqTvUJIFouxntxvraBj4T/hoUaUxjA5ICCekzQJqxbw+eucZHIIGbOcpetMqkWvNHSvmDNYUYdNqVe39q0EuSDDnf0KJtBSWJfGUqznyVUUDF6IiwUbC3ySbrAzpfbI2EX298rNkE/lHynl4pI+tCgaw2u6slRgLkkg7rj+/EMW/STDwqTsRKz5fCTL9wVbYloSvdNvoKSAOZx4N0UYaX4CHWgd+aQOm6HtslTo4UX+awZGTkFd12M4SkA0MgjKQaipAtyDYcaal+KJaU5cVBhtalHaMipsb2RBVWfTp5Y+ut4ojd51gjFNk4NW7BWyrIDyPOI/JTIesvp0PmtunXsFu5rFO+KPQK7SR/M2S+DD9IMMr8utVSnc2gb/Ow1crDcRadJ7qu4pLL+7a+Jk8GF/FR6iUcHZq2OWjRDubNePvVEVqeg8S2IC/Wc4yFM8PLVHqy3p8vi1BN0EoUd2epwRPNmXebb6XLU+ozrhfG46CdKwThsO0D/XZyVqivKXrdy1RVwpmBC0B8aA4V1if7667jsOJJ1UaBIpSoWwCRTdvMfnD4CWzUIYRDB5NEPx3wNJUlaletRYxG/ByvywjRQQrZMaDulKE7PpTA+u60gpnZezid9IdUrtrCE6U7Y01M7DDUuh7qm25HZdTNPj0+VWff40kW3HtFxIaWZ0Ioc13+8MzbiJXfByrAdBZNN8VkdMs8UiZGOsJslH72/AkRk3GFGj28MZwXPMDyJ1Z5gmn+WFNstMBw2kRzeUBv7leb8TfsUf3qgjh0/BLixy/vMggIAh8HSe9UDMWPMNKCKmvzMRIBkN50whe+J/4Hty/32oGmbzy26DEtwUo62P7x7UdnkgHmChUOQ43UQK2NIPNKPNZYFYk4GD1jJUSMhY2fF0iWubDnML79waeb4tKN6xCDSZ2brLSWnsiKl4kFOCWJOgXpMS3JKkYr3ygPkiJYc34kp61JYh9Ya9fxAKB0UcMA/ejuoW9XY7DU7b6XnsvDOVEbcU44dO/1qphe40BVlw7Wd1ythfLBxY1teKddSm7yhTmWMOMeeNb7ZSVwg+P13Orvb9XQQSfSrmn26EHy/kWlNTd+rK4YFUfkjdRdhHpbTTAhnusbrLoDm3xSj2jaxQbTT+r3BV1NNdTOJ2hTai0kL9eqovcp2TaPZiO0uqifvProAfQNPIZO7mkbgErFHLiknc49oMkg0AYzRexVtXWckFOpqb71RR+CiXj1mlPXayHrZLn8L+sdKsMvuWE0/ZDzPtfo0ohi7ArhSwyHaVVpoKkBYheBshcHa48Ug2MaVdDj5JbQgDW3ij822kj/XAqCA3J1Sv5GuWsJ46DL0uKIPaP6g0KHJLNg5l0oHTmVLwFuPtiDBtGVWVjg1rfkEA7NXNWCoW5OXjMEAaadSuVBEDW5h8SbPcEwPO4HnZYMJixseFh9l7w9YvcqE1eepZZuD4l8GgcNqgu5Y8bLluLRHeVNOpn+ke9j2E4 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0d2ec48-80f8-4898-5ea5-08dadd55f93e X-MS-Exchange-CrossTenant-AuthSource: HE1PR0401MB2331.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 22:04:16.8511 (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: 41672o7JSVFCbsL3ZztdvDdSGSfIFxbDO7ANJEzQlYMUO21KR7GOT1aKhSVav8x3l5rpA4PZ0MK1M4TWIDr2XA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7196 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_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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: <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?1752138161721213325?= X-GMAIL-MSGID: =?utf-8?q?1752138161721213325?= |
Series |
[v2,1/1] usb: gadget: Assign an unique name for each configfs driver
|
|
Commit Message
Frank Li
Dec. 13, 2022, 10:03 p.m. UTC
From: Rondreis <linhaoguo86@gmail.com> When use configfs to attach more than one gadget. Error: Driver 'configfs-gadget' is already registered, aborting... UDC core: g1: driver registration failed: -16 The problem is that when creating multiple gadgets with configfs and binding them to different UDCs, the UDC drivers have the same name "configfs-gadget". Because of the addition of the "gadget" bus, naming conflicts will occur when more than one UDC drivers registered to the bus. It's not an isolated case, this patch refers to the commit f2d8c2606825 ("usb: gadget: Fix non-unique driver names in raw-gadget driver"). Each configfs-gadget driver will be assigned a unique name "configfs-gadget.N", with a different value of N for each driver instance. Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") Signed-off-by: Rondreis <linhaoguo86@gmail.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> --- This patch is based on https://lore.kernel.org/lkml/20220907112210.11949-1-linhaoguo86@gmail.com/ fixed the all greg's comments. I met the same issue. Look likes Rodrieis have not continue to work this patch since Sep, 2022. I don't know full name of Rondreis. drivers/usb/gadget/configfs.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
Comments
Le 13/12/2022 à 23:03, Frank Li a écrit : > From: Rondreis <linhaoguo86@gmail.com> > > When use configfs to attach more than one gadget. > > Error: Driver 'configfs-gadget' is already registered, aborting... > > UDC core: g1: driver registration failed: -16 > > The problem is that when creating multiple gadgets with configfs and > binding them to different UDCs, the UDC drivers have the same name > "configfs-gadget". Because of the addition of the "gadget" bus, naming > conflicts will occur when more than one UDC drivers registered to the > bus. > > It's not an isolated case, this patch refers to the commit f2d8c2606825 > ("usb: gadget: Fix non-unique driver names in raw-gadget driver"). > Each configfs-gadget driver will be assigned a unique name > "configfs-gadget.N", with a different value of N for each driver > instance. > > Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") > > Signed-off-by: Rondreis <linhaoguo86@gmail.com> > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > > This patch is based on https://lore.kernel.org/lkml/20220907112210.11949-1-linhaoguo86@gmail.com/ > fixed the all greg's comments. > > I met the same issue. Look likes Rodrieis have not continue to work this > patch since Sep, 2022. > > I don't know full name of Rondreis. Hi, Also, out of curiosity, any link with this patch: https://lore.kernel.org/all/20221213041203.21080-1-chanh@os.amperecomputing.com/ ? Not exactly the same, but not very different. (adding Chanh Nguyen in cc) CJ > > drivers/usb/gadget/configfs.c | 30 ++++++++++++++++++++++++++---- > 1 file changed, 26 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c > index 3a6b4926193e..785be6aea720 100644 > --- a/drivers/usb/gadget/configfs.c > +++ b/drivers/usb/gadget/configfs.c > @@ -4,12 +4,17 @@ > #include <linux/slab.h> > #include <linux/device.h> > #include <linux/nls.h> > +#include <linux/idr.h> > #include <linux/usb/composite.h> > #include <linux/usb/gadget_configfs.h> > #include "configfs.h" > #include "u_f.h" > #include "u_os_desc.h" > > +#define DRIVER_NAME "configfs-gadget" > + > +static DEFINE_IDA(driver_id_numbers); > + > int check_user_usb_string(const char *name, > struct usb_gadget_strings *stringtab_dev) > { > @@ -46,6 +51,7 @@ struct gadget_info { > > struct usb_composite_driver composite; > struct usb_composite_dev cdev; > + int driver_id_number; > bool use_os_desc; > char b_vendor_code; > char qw_sign[OS_STRING_QW_SIGN_LEN]; > @@ -392,6 +398,8 @@ static void gadget_info_attr_release(struct config_item *item) > WARN_ON(!list_empty(&gi->string_list)); > WARN_ON(!list_empty(&gi->available_func)); > kfree(gi->composite.gadget_driver.function); > + kfree(gi->composite.gadget_driver.driver.name); > + ida_free(&driver_id_numbers, gi->driver_id_number); > kfree(gi); > } > > @@ -1571,7 +1579,6 @@ static const struct usb_gadget_driver configfs_driver_template = { > .max_speed = USB_SPEED_SUPER_PLUS, > .driver = { > .owner = THIS_MODULE, > - .name = "configfs-gadget", > }, > .match_existing_only = 1, > }; > @@ -1581,6 +1588,7 @@ static struct config_group *gadgets_make( > const char *name) > { > struct gadget_info *gi; > + int ret = 0; > > gi = kzalloc(sizeof(*gi), GFP_KERNEL); > if (!gi) > @@ -1622,16 +1630,30 @@ static struct config_group *gadgets_make( > > gi->composite.gadget_driver = configfs_driver_template; > > + ret = ida_alloc(&driver_id_numbers, GFP_KERNEL); > + if (ret < 0) > + goto err; > + gi->driver_id_number = ret; > + > + gi->composite.gadget_driver.driver.name = > + kasprintf(GFP_KERNEL, DRIVER_NAME ".%d", gi->driver_id_number); > + > gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); > gi->composite.name = gi->composite.gadget_driver.function; > > - if (!gi->composite.gadget_driver.function) > - goto err; > + if (!gi->composite.gadget_driver.function) { > + ret = -ENOMEM; > + goto err_func; > + } > > return &gi->group; > + > +err_func: > + kfree(gi->composite.gadget_driver.driver.name); > + ida_free(&driver_id_numbers, gi->driver_id_number); > err: > kfree(gi); > - return ERR_PTR(-ENOMEM); > + return ERR_PTR(ret); > } > > static void gadgets_drop(struct config_group *group, struct config_item *item)
> > Hi, > > Also, out of curiosity, any link with this patch: > > https://lore.kernel.org/all/20221213041203.21080-1-chanh@os.amperecomputing.com/ > > Not exactly the same, but not very different. > > (adding Chanh Nguyen in cc) Yes, it is almost the same. I think it is not good place to free driver.name at gadget_drop function(), it should be close to kfree(gi). > > CJ >
On Tue, Dec 13, 2022 at 05:03:54PM -0500, Frank Li wrote: > From: Rondreis <linhaoguo86@gmail.com> > > When use configfs to attach more than one gadget. > > Error: Driver 'configfs-gadget' is already registered, aborting... > > UDC core: g1: driver registration failed: -16 > > The problem is that when creating multiple gadgets with configfs and > binding them to different UDCs, the UDC drivers have the same name > "configfs-gadget". Because of the addition of the "gadget" bus, naming > conflicts will occur when more than one UDC drivers registered to the > bus. > > It's not an isolated case, this patch refers to the commit f2d8c2606825 > ("usb: gadget: Fix non-unique driver names in raw-gadget driver"). > Each configfs-gadget driver will be assigned a unique name > "configfs-gadget.N", with a different value of N for each driver > instance. > > Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") > > Signed-off-by: Rondreis <linhaoguo86@gmail.com> > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > > This patch is based on https://lore.kernel.org/lkml/20220907112210.11949-1-linhaoguo86@gmail.com/ > fixed the all greg's comments. > > I met the same issue. Look likes Rodrieis have not continue to work this > patch since Sep, 2022. > > I don't know full name of Rondreis. > > drivers/usb/gadget/configfs.c | 30 ++++++++++++++++++++++++++---- > 1 file changed, 26 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c > index 3a6b4926193e..785be6aea720 100644 > --- a/drivers/usb/gadget/configfs.c > +++ b/drivers/usb/gadget/configfs.c > @@ -4,12 +4,17 @@ > #include <linux/slab.h> > #include <linux/device.h> > #include <linux/nls.h> > +#include <linux/idr.h> > #include <linux/usb/composite.h> > #include <linux/usb/gadget_configfs.h> > #include "configfs.h" > #include "u_f.h" > #include "u_os_desc.h" > > +#define DRIVER_NAME "configfs-gadget" > + > +static DEFINE_IDA(driver_id_numbers); > + > int check_user_usb_string(const char *name, > struct usb_gadget_strings *stringtab_dev) > { > @@ -46,6 +51,7 @@ struct gadget_info { > > struct usb_composite_driver composite; > struct usb_composite_dev cdev; > + int driver_id_number; > bool use_os_desc; > char b_vendor_code; > char qw_sign[OS_STRING_QW_SIGN_LEN]; > @@ -392,6 +398,8 @@ static void gadget_info_attr_release(struct config_item *item) > WARN_ON(!list_empty(&gi->string_list)); > WARN_ON(!list_empty(&gi->available_func)); > kfree(gi->composite.gadget_driver.function); > + kfree(gi->composite.gadget_driver.driver.name); > + ida_free(&driver_id_numbers, gi->driver_id_number); > kfree(gi); > } > > @@ -1571,7 +1579,6 @@ static const struct usb_gadget_driver configfs_driver_template = { > .max_speed = USB_SPEED_SUPER_PLUS, > .driver = { > .owner = THIS_MODULE, > - .name = "configfs-gadget", > }, > .match_existing_only = 1, > }; > @@ -1581,6 +1588,7 @@ static struct config_group *gadgets_make( > const char *name) > { > struct gadget_info *gi; > + int ret = 0; > > gi = kzalloc(sizeof(*gi), GFP_KERNEL); > if (!gi) > @@ -1622,16 +1630,30 @@ static struct config_group *gadgets_make( > > gi->composite.gadget_driver = configfs_driver_template; > > + ret = ida_alloc(&driver_id_numbers, GFP_KERNEL); > + if (ret < 0) > + goto err; > + gi->driver_id_number = ret; > + > + gi->composite.gadget_driver.driver.name = > + kasprintf(GFP_KERNEL, DRIVER_NAME ".%d", gi->driver_id_number); Here you forgot to put: if (!gi->composite.gadget_driver.driver.name) { ret = -ENOMEM; goto err_func; } Or if you prefer, combine this test with the one below. Alan Stern > + > gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); > gi->composite.name = gi->composite.gadget_driver.function; > > - if (!gi->composite.gadget_driver.function) > - goto err; > + if (!gi->composite.gadget_driver.function) { > + ret = -ENOMEM; > + goto err_func; > + } > > return &gi->group; > + > +err_func: > + kfree(gi->composite.gadget_driver.driver.name); > + ida_free(&driver_id_numbers, gi->driver_id_number); > err: > kfree(gi); > - return ERR_PTR(-ENOMEM); > + return ERR_PTR(ret); > } > > static void gadgets_drop(struct config_group *group, struct config_item *item) > -- > 2.34.1 >
On 14/12/2022 05:20, Christophe JAILLET wrote: > Le 13/12/2022 à 23:03, Frank Li a écrit : >> From: Rondreis <linhaoguo86@gmail.com> >> >> When use configfs to attach more than one gadget. >> >> Error: Driver 'configfs-gadget' is already registered, aborting... >> >> UDC core: g1: driver registration failed: -16 >> >> The problem is that when creating multiple gadgets with configfs and >> binding them to different UDCs, the UDC drivers have the same name >> "configfs-gadget". Because of the addition of the "gadget" bus, naming >> conflicts will occur when more than one UDC drivers registered to the >> bus. >> >> It's not an isolated case, this patch refers to the commit f2d8c2606825 >> ("usb: gadget: Fix non-unique driver names in raw-gadget driver"). >> Each configfs-gadget driver will be assigned a unique name >> "configfs-gadget.N", with a different value of N for each driver >> instance. >> >> Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") >> >> Signed-off-by: Rondreis <linhaoguo86@gmail.com> >> Signed-off-by: Frank Li <Frank.Li@nxp.com> >> --- >> >> This patch is based on >> https://lore.kernel.org/lkml/20220907112210.11949-1-linhaoguo86@gmail.com/ >> fixed the all greg's comments. >> >> I met the same issue. Look likes Rodrieis have not continue to work this >> patch since Sep, 2022. >> >> I don't know full name of Rondreis. > > Hi, > > Also, out of curiosity, any link with this patch: > > https://lore.kernel.org/all/20221213041203.21080-1-chanh@os.amperecomputing.com/ > ? > > Not exactly the same, but not very different. > > (adding Chanh Nguyen in cc) > What a coincident :-) I did not aware there are some similar attempts to fix the same issue and see both patches posted same time. We start to see the issue when OpenBMC started to adopt kernel 6.0 and try to fix the issue since then (beginning of Oct 2022) We then could be able to identify the issue and try to fix it follow the commit f2d8c2606825317b77db1f9ba0fc26ef26160b30 Going forward, as we have both Frank and Rondreis interested in the patch, we are really happy if you both could review and share the comment. I'd really appreciate if you could help with that part. FYI, we have reviewed and made some changes based on CJ's comment in my last patch (v1) yesterday. We are trying to test it as much as possible. If it looks good we will re-post it as v2 shortly for further comment. Thanks a lot for interesting in the patch. - Chanh > >> >> drivers/usb/gadget/configfs.c | 30 ++++++++++++++++++++++++++---- >> 1 file changed, 26 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/usb/gadget/configfs.c >> b/drivers/usb/gadget/configfs.c >> index 3a6b4926193e..785be6aea720 100644 >> --- a/drivers/usb/gadget/configfs.c >> +++ b/drivers/usb/gadget/configfs.c >> @@ -4,12 +4,17 @@ >> #include <linux/slab.h> >> #include <linux/device.h> >> #include <linux/nls.h> >> +#include <linux/idr.h> >> #include <linux/usb/composite.h> >> #include <linux/usb/gadget_configfs.h> >> #include "configfs.h" >> #include "u_f.h" >> #include "u_os_desc.h" >> +#define DRIVER_NAME "configfs-gadget" >> + >> +static DEFINE_IDA(driver_id_numbers); >> + >> int check_user_usb_string(const char *name, >> struct usb_gadget_strings *stringtab_dev) >> { >> @@ -46,6 +51,7 @@ struct gadget_info { >> struct usb_composite_driver composite; >> struct usb_composite_dev cdev; >> + int driver_id_number; >> bool use_os_desc; >> char b_vendor_code; >> char qw_sign[OS_STRING_QW_SIGN_LEN]; >> @@ -392,6 +398,8 @@ static void gadget_info_attr_release(struct >> config_item *item) >> WARN_ON(!list_empty(&gi->string_list)); >> WARN_ON(!list_empty(&gi->available_func)); >> kfree(gi->composite.gadget_driver.function); >> + kfree(gi->composite.gadget_driver.driver.name); >> + ida_free(&driver_id_numbers, gi->driver_id_number); >> kfree(gi); >> } >> @@ -1571,7 +1579,6 @@ static const struct usb_gadget_driver >> configfs_driver_template = { >> .max_speed = USB_SPEED_SUPER_PLUS, >> .driver = { >> .owner = THIS_MODULE, >> - .name = "configfs-gadget", >> }, >> .match_existing_only = 1, >> }; >> @@ -1581,6 +1588,7 @@ static struct config_group *gadgets_make( >> const char *name) >> { >> struct gadget_info *gi; >> + int ret = 0; >> gi = kzalloc(sizeof(*gi), GFP_KERNEL); >> if (!gi) >> @@ -1622,16 +1630,30 @@ static struct config_group *gadgets_make( >> gi->composite.gadget_driver = configfs_driver_template; >> + ret = ida_alloc(&driver_id_numbers, GFP_KERNEL); >> + if (ret < 0) >> + goto err; >> + gi->driver_id_number = ret; >> + >> + gi->composite.gadget_driver.driver.name = >> + kasprintf(GFP_KERNEL, DRIVER_NAME ".%d", gi->driver_id_number); >> + >> gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); >> gi->composite.name = gi->composite.gadget_driver.function; >> - if (!gi->composite.gadget_driver.function) >> - goto err; >> + if (!gi->composite.gadget_driver.function) { >> + ret = -ENOMEM; >> + goto err_func; >> + } >> return &gi->group; >> + >> +err_func: >> + kfree(gi->composite.gadget_driver.driver.name); >> + ida_free(&driver_id_numbers, gi->driver_id_number); >> err: >> kfree(gi); >> - return ERR_PTR(-ENOMEM); >> + return ERR_PTR(ret); >> } >> static void gadgets_drop(struct config_group *group, struct >> config_item *item) >
> -----Original Message----- > From: Chanh Nguyen <chanh@amperemail.onmicrosoft.com> > Sent: Tuesday, December 13, 2022 9:38 PM > To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>; Frank Li > <frank.li@nxp.com> > Cc: balbi@kernel.org; gregkh@linuxfoundation.org; imx@lists.linux.dev; > linhaoguo86@gmail.com; linux-kernel@vger.kernel.org; linux- > usb@vger.kernel.org; stern@rowland.harvard.edu; Chanh Nguyen > <chanh@os.amperecomputing.com> > Subject: [EXT] Re: [PATCH v2 1/1] usb: gadget: Assign an unique name for > each configfs driver > > Caution: EXT Email > > On 14/12/2022 05:20, Christophe JAILLET wrote: > > Le 13/12/2022 à 23:03, Frank Li a écrit : > >> From: Rondreis <linhaoguo86@gmail.com> > >> > >> When use configfs to attach more than one gadget. > >> > >> Error: Driver 'configfs-gadget' is already registered, aborting... > >> > >> UDC core: g1: driver registration failed: -16 > >> > >> The problem is that when creating multiple gadgets with configfs and > >> binding them to different UDCs, the UDC drivers have the same name > >> "configfs-gadget". Because of the addition of the "gadget" bus, naming > >> conflicts will occur when more than one UDC drivers registered to the > >> bus. > >> > >> It's not an isolated case, this patch refers to the commit f2d8c2606825 > >> ("usb: gadget: Fix non-unique driver names in raw-gadget driver"). > >> Each configfs-gadget driver will be assigned a unique name > >> "configfs-gadget.N", with a different value of N for each driver > >> instance. > >> > >> Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets") > >> > >> Signed-off-by: Rondreis <linhaoguo86@gmail.com> > >> Signed-off-by: Frank Li <Frank.Li@nxp.com> > >> --- > >> > >> This patch is based on > >> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.k > ernel.org%2Flkml%2F20220907112210.11949-1- > linhaoguo86%40gmail.com%2F&data=05%7C01%7CFrank.Li%40nxp.com > %7C1c0810ddd7e94971373208dadd849636%7C686ea1d3bc2b4c6fa92cd99c5c3 > 01635%7C0%7C0%7C638065858780321185%7CUnknown%7CTWFpbGZsb3d8e > yJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D > %7C3000%7C%7C%7C&sdata=dDLDGL9ie0hzjPa44qHt2oAnIurcZo01Mcz > xBAjUoQk%3D&reserved=0 > >> fixed the all greg's comments. > >> > >> I met the same issue. Look likes Rodrieis have not continue to work this > >> patch since Sep, 2022. > >> > >> I don't know full name of Rondreis. > > > > Hi, > > > > Also, out of curiosity, any link with this patch: > > > > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.k > ernel.org%2Fall%2F20221213041203.21080-1- > chanh%40os.amperecomputing.com%2F&data=05%7C01%7CFrank.Li%4 > 0nxp.com%7C1c0810ddd7e94971373208dadd849636%7C686ea1d3bc2b4c6fa9 > 2cd99c5c301635%7C0%7C0%7C638065858780321185%7CUnknown%7CTWFpb > GZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI > 6Mn0%3D%7C3000%7C%7C%7C&sdata=HuD9mWg4D%2B%2BOPjUA6b > 0DoktyubY52TwtWdEpMuMfuk0%3D&reserved=0 > > ? > > > > Not exactly the same, but not very different. > > > > (adding Chanh Nguyen in cc) > > > > What a coincident :-) > > I did not aware there are some similar attempts to fix the same issue > and see both patches posted same time. > > We start to see the issue when OpenBMC started to adopt kernel 6.0 and > try to fix the issue since then (beginning of Oct 2022) > > We then could be able to identify the issue and try to fix it follow the > commit f2d8c2606825317b77db1f9ba0fc26ef26160b30 > > Going forward, as we have both Frank and Rondreis interested in the > patch, we are really happy if you both could review and share the > comment. I'd really appreciate if you could help with that part. > > FYI, we have reviewed and made some changes based on CJ's comment in > my > last patch (v1) yesterday. We are trying to test it as much as possible. > If it looks good we will re-post it as v2 shortly for further comment. I almost just reused rondreis patch. I can review your v2 version. I prefer move kfree(gi->composite.gadget_driver.driver.name) into gadget_info_attr_release, just before free(gi). Best regards Frank Li > > Thanks a lot for interesting in the patch. > - Chanh > > > > >> > >> drivers/usb/gadget/configfs.c | 30 ++++++++++++++++++++++++++---- > >> 1 file changed, 26 insertions(+), 4 deletions(-) > >> > >> diff --git a/drivers/usb/gadget/configfs.c > >> b/drivers/usb/gadget/configfs.c > >> index 3a6b4926193e..785be6aea720 100644 > >> --- a/drivers/usb/gadget/configfs.c > >> +++ b/drivers/usb/gadget/configfs.c > >> @@ -4,12 +4,17 @@ > >> #include <linux/slab.h> > >> #include <linux/device.h> > >> #include <linux/nls.h> > >> +#include <linux/idr.h> > >> #include <linux/usb/composite.h> > >> #include <linux/usb/gadget_configfs.h> > >> #include "configfs.h" > >> #include "u_f.h" > >> #include "u_os_desc.h" > >> +#define DRIVER_NAME "configfs-gadget" > >> + > >> +static DEFINE_IDA(driver_id_numbers); > >> + > >> int check_user_usb_string(const char *name, > >> struct usb_gadget_strings *stringtab_dev) > >> { > >> @@ -46,6 +51,7 @@ struct gadget_info { > >> struct usb_composite_driver composite; > >> struct usb_composite_dev cdev; > >> + int driver_id_number; > >> bool use_os_desc; > >> char b_vendor_code; > >> char qw_sign[OS_STRING_QW_SIGN_LEN]; > >> @@ -392,6 +398,8 @@ static void gadget_info_attr_release(struct > >> config_item *item) > >> WARN_ON(!list_empty(&gi->string_list)); > >> WARN_ON(!list_empty(&gi->available_func)); > >> kfree(gi->composite.gadget_driver.function); > >> + kfree(gi->composite.gadget_driver.driver.name); > >> + ida_free(&driver_id_numbers, gi->driver_id_number); > >> kfree(gi); > >> } > >> @@ -1571,7 +1579,6 @@ static const struct usb_gadget_driver > >> configfs_driver_template = { > >> .max_speed = USB_SPEED_SUPER_PLUS, > >> .driver = { > >> .owner = THIS_MODULE, > >> - .name = "configfs-gadget", > >> }, > >> .match_existing_only = 1, > >> }; > >> @@ -1581,6 +1588,7 @@ static struct config_group *gadgets_make( > >> const char *name) > >> { > >> struct gadget_info *gi; > >> + int ret = 0; > >> gi = kzalloc(sizeof(*gi), GFP_KERNEL); > >> if (!gi) > >> @@ -1622,16 +1630,30 @@ static struct config_group *gadgets_make( > >> gi->composite.gadget_driver = configfs_driver_template; > >> + ret = ida_alloc(&driver_id_numbers, GFP_KERNEL); > >> + if (ret < 0) > >> + goto err; > >> + gi->driver_id_number = ret; > >> + > >> + gi->composite.gadget_driver.driver.name = > >> + kasprintf(GFP_KERNEL, DRIVER_NAME ".%d", gi- > >driver_id_number); > >> + > >> gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); > >> gi->composite.name = gi->composite.gadget_driver.function; > >> - if (!gi->composite.gadget_driver.function) > >> - goto err; > >> + if (!gi->composite.gadget_driver.function) { > >> + ret = -ENOMEM; > >> + goto err_func; > >> + } > >> return &gi->group; > >> + > >> +err_func: > >> + kfree(gi->composite.gadget_driver.driver.name); > >> + ida_free(&driver_id_numbers, gi->driver_id_number); > >> err: > >> kfree(gi); > >> - return ERR_PTR(-ENOMEM); > >> + return ERR_PTR(ret); > >> } > >> static void gadgets_drop(struct config_group *group, struct > >> config_item *item) > >
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 3a6b4926193e..785be6aea720 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -4,12 +4,17 @@ #include <linux/slab.h> #include <linux/device.h> #include <linux/nls.h> +#include <linux/idr.h> #include <linux/usb/composite.h> #include <linux/usb/gadget_configfs.h> #include "configfs.h" #include "u_f.h" #include "u_os_desc.h" +#define DRIVER_NAME "configfs-gadget" + +static DEFINE_IDA(driver_id_numbers); + int check_user_usb_string(const char *name, struct usb_gadget_strings *stringtab_dev) { @@ -46,6 +51,7 @@ struct gadget_info { struct usb_composite_driver composite; struct usb_composite_dev cdev; + int driver_id_number; bool use_os_desc; char b_vendor_code; char qw_sign[OS_STRING_QW_SIGN_LEN]; @@ -392,6 +398,8 @@ static void gadget_info_attr_release(struct config_item *item) WARN_ON(!list_empty(&gi->string_list)); WARN_ON(!list_empty(&gi->available_func)); kfree(gi->composite.gadget_driver.function); + kfree(gi->composite.gadget_driver.driver.name); + ida_free(&driver_id_numbers, gi->driver_id_number); kfree(gi); } @@ -1571,7 +1579,6 @@ static const struct usb_gadget_driver configfs_driver_template = { .max_speed = USB_SPEED_SUPER_PLUS, .driver = { .owner = THIS_MODULE, - .name = "configfs-gadget", }, .match_existing_only = 1, }; @@ -1581,6 +1588,7 @@ static struct config_group *gadgets_make( const char *name) { struct gadget_info *gi; + int ret = 0; gi = kzalloc(sizeof(*gi), GFP_KERNEL); if (!gi) @@ -1622,16 +1630,30 @@ static struct config_group *gadgets_make( gi->composite.gadget_driver = configfs_driver_template; + ret = ida_alloc(&driver_id_numbers, GFP_KERNEL); + if (ret < 0) + goto err; + gi->driver_id_number = ret; + + gi->composite.gadget_driver.driver.name = + kasprintf(GFP_KERNEL, DRIVER_NAME ".%d", gi->driver_id_number); + gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); gi->composite.name = gi->composite.gadget_driver.function; - if (!gi->composite.gadget_driver.function) - goto err; + if (!gi->composite.gadget_driver.function) { + ret = -ENOMEM; + goto err_func; + } return &gi->group; + +err_func: + kfree(gi->composite.gadget_driver.driver.name); + ida_free(&driver_id_numbers, gi->driver_id_number); err: kfree(gi); - return ERR_PTR(-ENOMEM); + return ERR_PTR(ret); } static void gadgets_drop(struct config_group *group, struct config_item *item)