Skip to content

Commit 7c07553

Browse files
chnguyen-amperegregkh
authored andcommitted
USB: gadget: Add ID numbers to configfs-gadget driver names
It is unable to use configfs to attach more than one gadget. When attaching the second gadget, it always fails and the kernel message prints out: Error: Driver 'configfs-gadget' is already registered, aborting... UDC core: g1: driver registration failed: -16 This commit fixes the problem by using the gadget name as a suffix to each configfs_gadget's driver name, thus making the names distinct. Fixes: fc274c1 ("USB: gadget: Add a new bus for gadgets") Cc: stable <[email protected]> Signed-off-by: Chanh Nguyen <[email protected]> Reviewed-by: Andrzej Pietrasiewicz <[email protected]> Tested-by: Heikki Krogerus <[email protected]> Reviewed-by: Frank Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 36f7847 commit 7c07553

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/usb/gadget/configfs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static void gadget_info_attr_release(struct config_item *item)
393393
WARN_ON(!list_empty(&gi->string_list));
394394
WARN_ON(!list_empty(&gi->available_func));
395395
kfree(gi->composite.gadget_driver.function);
396+
kfree(gi->composite.gadget_driver.driver.name);
396397
kfree(gi);
397398
}
398399

@@ -1572,7 +1573,6 @@ static const struct usb_gadget_driver configfs_driver_template = {
15721573
.max_speed = USB_SPEED_SUPER_PLUS,
15731574
.driver = {
15741575
.owner = THIS_MODULE,
1575-
.name = "configfs-gadget",
15761576
},
15771577
.match_existing_only = 1,
15781578
};
@@ -1623,13 +1623,21 @@ static struct config_group *gadgets_make(
16231623

16241624
gi->composite.gadget_driver = configfs_driver_template;
16251625

1626+
gi->composite.gadget_driver.driver.name = kasprintf(GFP_KERNEL,
1627+
"configfs-gadget.%s", name);
1628+
if (!gi->composite.gadget_driver.driver.name)
1629+
goto err;
1630+
16261631
gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL);
16271632
gi->composite.name = gi->composite.gadget_driver.function;
16281633

16291634
if (!gi->composite.gadget_driver.function)
1630-
goto err;
1635+
goto out_free_driver_name;
16311636

16321637
return &gi->group;
1638+
1639+
out_free_driver_name:
1640+
kfree(gi->composite.gadget_driver.driver.name);
16331641
err:
16341642
kfree(gi);
16351643
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)