Skip to content

Commit

Permalink
USB: gadget: Add ID numbers to configfs-gadget driver names
Browse files Browse the repository at this point in the history
commit 7c07553 upstream.

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 <stable@kernel.org>
Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com>
Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Tested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Frank Li <frank.li@nxp.com>
Link: https://lore.kernel.org/r/20230111065105.29205-1-chanh@os.amperecomputing.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
chnguyen-ampere authored and gregkh committed Jan 24, 2023
1 parent f9c8c6b commit 96abcf7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/usb/gadget/configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ 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);
kfree(gi);
}

Expand Down Expand Up @@ -1571,7 +1572,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,
};
Expand Down Expand Up @@ -1622,13 +1622,21 @@ static struct config_group *gadgets_make(

gi->composite.gadget_driver = configfs_driver_template;

gi->composite.gadget_driver.driver.name = kasprintf(GFP_KERNEL,
"configfs-gadget.%s", name);
if (!gi->composite.gadget_driver.driver.name)
goto err;

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;
goto out_free_driver_name;

return &gi->group;

out_free_driver_name:
kfree(gi->composite.gadget_driver.driver.name);
err:
kfree(gi);
return ERR_PTR(-ENOMEM);
Expand Down

0 comments on commit 96abcf7

Please sign in to comment.