Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp125510iob; Tue, 3 May 2022 13:07:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhgYCJPUNE5mgtJVnbRZM8m/1/1+lhI3kuizgA3sicIt338IwIIBhJU1j3LnH2DLyA/pH7 X-Received: by 2002:a17:902:db07:b0:15e:b669:42a2 with SMTP id m7-20020a170902db0700b0015eb66942a2mr4918235plx.80.1651608444155; Tue, 03 May 2022 13:07:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608444; cv=none; d=google.com; s=arc-20160816; b=F+6fDYbrKvzJ1oewXcUxmlxF8VABAfCnKDQYlt3DkeXt3kJYjRWGRMK6jtvruNJG+r WOytoPF9kWBsqQ4FhGpVoxDnkV8A7ifyPiuC0MKtCx08Zulh5Ashfe07sxBgjTCqLvVh DSZkYnQ4Eq19lF7NW60Mvi7rSZ0/nVi4xoNb/NWKDGOVM09Tu+KcFLuU4YXuKQVA5I/v MAag+MnKZ19vebosWLpslLweZfOMbPKvoS4k2qGFK2P0H34iajGDZcMoohY8bxHqMw/p +pODzQCQk9bkUe1d8VKWLOODFyfm8pKH5WUdb8zXjMmAeds1Z5Tok2bdTAT9aqi0D/xW 4Yng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=dd5GPQVu/87pER1FRQdVdwT8os0PuczxiVMhrWNXuDE=; b=EU4BPxBCYoNe5T2ss443wOT92HcA7nMRyOGZgfjsYFb5fki9SRu5D+b9k04aQKWrRY laVHPgxEuZD+ay4lS7VxzheRwv8MKn/SvD3M8mJtwFvbUs7rbp3rKZB2PMljmqKbu5yB LJCANk1iD5pZMwTwPsrMkjSn6km8FvK9PMRaGeB2TvmQzGhe6ZoTvCqUTtvTElyQQxul n4//72l83KIZ93Q5Fm1ZMPSZhbT2aJSgGH6tJgHAsMoRy1GUCExpDh/phF8ZfQ5OVI6Z ZOZYrXf8xFY5X6yUrxd+b7PBvKHfNTezOXiViryd5f08PoCNDkBLxisiyr7J/Ecp3LJ7 jYGg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 189-20020a6300c6000000b003aa7e24e0a6si17045628pga.536.2022.05.03.13.06.59; Tue, 03 May 2022 13:07: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238866AbiECPwK (ORCPT + 99 others); Tue, 3 May 2022 11:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238616AbiECPwI (ORCPT ); Tue, 3 May 2022 11:52:08 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id E2262369D1 for ; Tue, 3 May 2022 08:48:34 -0700 (PDT) Received: (qmail 1090066 invoked by uid 1000); 3 May 2022 11:48:33 -0400 Date: Tue, 3 May 2022 11:48:33 -0400 From: Alan Stern To: Geert Uytterhoeven Cc: Felipe Balbi , Greg KH , USB mailing list , Linux-Renesas , Linux Kernel Mailing List , Yoshihiro Shimoda Subject: Re: [PATCH 4/4] USB: gadget: Add a new bus for gadgets Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue, May 03, 2022 at 05:27:08PM +0200, Geert Uytterhoeven wrote: > Hi Alan, > > On Tue, May 3, 2022 at 5:14 PM Alan Stern wrote: > > On Tue, May 03, 2022 at 12:14:30PM +0200, Geert Uytterhoeven wrote: > > > On Sat, 23 Apr 2022, Alan Stern wrote: > > > > This patch adds a "gadget" bus and uses it for registering gadgets and > > > > their drivers. From now on, bindings will be managed by the driver > > > > core rather than through ad-hoc manipulations in the UDC core. > > > > > > > > As part of this change, the driver_pending_list is removed. The UDC > > > > core won't need to keep track of unbound drivers for later binding, > > > > because the driver core handles all of that for us. > > > > > > > > However, we do need one new feature: a way to prevent gadget drivers > > > > from being bound to more than one gadget at a time. The existing code > > > > does this automatically, but the driver core doesn't -- it's perfectly > > > > happy to bind a single driver to all the matching devices on the bus. > > > > The patch adds a new bitflag to the usb_gadget_driver structure for > > > > this purpose. > > > > > > > > A nice side effect of this change is a reduction in the total lines of > > > > code, since now the driver core will do part of the work that the UDC > > > > used to do. > > > > > > > > A possible future patch could add udc devices to the gadget bus, say > > > > as a separate device type. > > > > > > > > Signed-off-by: Alan Stern > > > > > > Thanks for your patch, which is now commit fc274c1e997314bf ("USB: > > > gadget: Add a new bus for gadgets") in usb-next. > > > > > > This patch cause a regression on the Renesas Salvator-XS development > > > board, as R-Car H3 has multiple USB gadget devices: > > > > Then these gadgets ought to have distinct names in order to avoid the > > conflict below: > > > > > sysfs: cannot create duplicate filename '/bus/gadget/devices/gadget' > > > CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.18.0-rc1-arm64-renesas-00074-gfc274c1e9973 #1587 > > > Hardware name: Renesas Salvator-X 2nd version board based on r8a77951 (DT) > > > Call trace: > > > dump_backtrace+0xcc/0xd8 > > > show_stack+0x14/0x30 > > > dump_stack_lvl+0x88/0xb0 > > > dump_stack+0x14/0x2c > > > sysfs_warn_dup+0x60/0x78 > > > sysfs_do_create_link_sd.isra.0+0xe4/0xf0 > > > sysfs_create_link+0x20/0x40 > > > bus_add_device+0x64/0x110 > > > device_add+0x31c/0x850 > > > usb_add_gadget+0x124/0x1a0 > > > usb_add_gadget_udc_release+0x1c/0x50 > > > usb_add_gadget_udc+0x10/0x18 > > > renesas_usb3_probe+0x450/0x728 > > ... > > > > Having three gadget devices, all named "gadget", doesn't seem like a > > good idea. > > I'm not so sure where these names are coming from. > `git grep '"gadget"'` points to the following likely targets: > > drivers/usb/gadget/udc/core.c: dev_set_name(&gadget->dev, "gadget"); > drivers/usb/renesas_usbhs/mod_gadget.c: gpriv->mod.name = "gadget"; > > Changing both names reveals the problem is actually caused by > the former ;-) Ah, good. One way to attack this would be to keep a static counter and dynamically set the name to "gadget.%d" using the counter's value. Or keep a bitmap of allocated gadget numbers and use the first available number. Felipe, Greg, any opinions? Ironically, the UDC driver itself provides a name in gadget->name. But that string isn't unique either (in renesas-usb3, for instance, it is always set to "renesas_usb3"), so it won't help solve this problem. > > This doesn't seem like it should be too hard to fix, although I'm not > > at all familiar with the renesas-usb3 driver. Do you know who maintains > > that driver? Is it you? > > Adding Shimoda-san to CC (but he's enjoying Golden Week). It looks like the problem has to be solved in the gadget core rather than in the UDC driver. So we won't need to modify the driver after all. Alan Stern