From: Chanh Nguyen <chanh@os.amperecomputing.com>
To: OpenBMC Maillist <openbmc@lists.ozlabs.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Frank Li <frank.li@nxp.com>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Dan Vacura <w36195@motorola.com>,
Jakob Koschel <jakobkoschel@gmail.com>,
Alan Stern <stern@rowland.harvard.edu>,
Vijayavardhan Vennapusa <vvreddy@codeaurora.org>,
Rondreis <linhaoguo86@gmail.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Open Source Submission <patches@amperecomputing.com>
Cc: Chanh Nguyen <chanh@os.amperecomputing.com>
Subject: [PATCH v2] USB: gadget: Add ID numbers to configfs-gadget driver names
Date: Wed, 21 Dec 2022 16:13:17 +0700 [thread overview]
Message-ID: <20221221091317.19380-1-chanh@os.amperecomputing.com> (raw)
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 a ".N" suffix added to each
configfs_gadget's driver name (where N is a unique ID number),
thus making the names distinct.
Fixes: fc274c1e9973 ("USB: gadget: Add a new bus for gadgets")
Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com>
---
Changes in v2:
- Replace scnprintf() by kasprintf() to simplify the code [CJ]
- Move the clean up code from gadgets_drop() to
gadget_info_attr_release() [Frank Li]
- Correct the resource free up in gadges_make() [Alan Stern]
- Remove the unnecessary variable in gadgets_make() [Chanh]
- Fixes minor grammar issue in commit message [Chanh]
---
drivers/usb/gadget/configfs.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 96121d1c8df4..7faf68bfa716 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -3,6 +3,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/device.h>
+#include <linux/idr.h>
#include <linux/kstrtox.h>
#include <linux/nls.h>
#include <linux/usb/composite.h>
@@ -11,6 +12,8 @@
#include "u_f.h"
#include "u_os_desc.h"
+static DEFINE_IDA(driver_id_numbers);
+
int check_user_usb_string(const char *name,
struct usb_gadget_strings *stringtab_dev)
{
@@ -52,6 +55,9 @@ struct gadget_info {
char qw_sign[OS_STRING_QW_SIGN_LEN];
spinlock_t spinlock;
bool unbind;
+
+ /* Make driver names unique */
+ int driver_id_number;
};
static inline struct gadget_info *to_gadget_info(struct config_item *item)
@@ -393,6 +399,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);
}
@@ -1623,13 +1631,28 @@ static struct config_group *gadgets_make(
gi->composite.gadget_driver = configfs_driver_template;
+ gi->driver_id_number = ida_alloc(&driver_id_numbers, GFP_KERNEL);
+ if (gi->driver_id_number < 0)
+ goto err;
+
+ gi->composite.gadget_driver.driver.name = kasprintf(GFP_KERNEL,
+ "configfs-gadget.%d",
+ gi->driver_id_number);
+ if (!gi->composite.gadget_driver.driver.name)
+ goto out_free_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;
+ goto out_free_driver_name;
return &gi->group;
+
+out_free_driver_name:
+ kfree(gi->composite.gadget_driver.driver.name);
+out_free_driver_id_number:
+ ida_free(&driver_id_numbers, gi->driver_id_number);
err:
kfree(gi);
return ERR_PTR(-ENOMEM);
--
2.17.1
next reply other threads:[~2022-12-21 9:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-21 9:13 Chanh Nguyen [this message]
2022-12-22 15:20 ` Andrzej Pietrasiewicz
2022-12-25 3:07 ` [EXT] " Frank Li
2022-12-30 10:29 ` Chanh Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221221091317.19380-1-chanh@os.amperecomputing.com \
--to=chanh@os.amperecomputing.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=frank.li@nxp.com \
--cc=gregkh@linuxfoundation.org \
--cc=jakobkoschel@gmail.com \
--cc=linhaoguo86@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=openbmc@lists.ozlabs.org \
--cc=patches@amperecomputing.com \
--cc=stern@rowland.harvard.edu \
--cc=vvreddy@codeaurora.org \
--cc=w36195@motorola.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®