usb: gadget: provide interface for legacy gadgets to get UDC name
authorMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 18 Feb 2016 10:34:43 +0000 (11:34 +0100)
committerFelipe Balbi <balbi@kernel.org>
Fri, 4 Mar 2016 13:14:35 +0000 (15:14 +0200)
Since commit 855ed04a3758b205e84b269f92d26ab36ed8e2f7 ("usb: gadget:
udc-core: independent registration of gadgets and gadget drivers") gadget
drivers can not assume that UDC drivers are already available on their
initialization. This broke the HACK, which was used in gadgetfs driver,
to get UDC controller name. This patch removes this hack and replaces it
by additional function in the UDC core (which is usefully only for legacy
drivers, please don't use it in the new code).

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
drivers/usb/gadget/legacy/inode.c
drivers/usb/gadget/udc/udc-core.c
include/linux/usb/gadget.h

index 87fb0fd6aaabea260758ba338769d6be70472740..5cdaf0150a4ed4fc2efe42c19dff6083674ead13 100644 (file)
@@ -1699,28 +1699,6 @@ static struct usb_gadget_driver gadgetfs_driver = {
 };
 
 /*----------------------------------------------------------------------*/
-
-static void gadgetfs_nop(struct usb_gadget *arg) { }
-
-static int gadgetfs_probe(struct usb_gadget *gadget,
-               struct usb_gadget_driver *driver)
-{
-       CHIP = gadget->name;
-       return -EISNAM;
-}
-
-static struct usb_gadget_driver probe_driver = {
-       .max_speed      = USB_SPEED_HIGH,
-       .bind           = gadgetfs_probe,
-       .unbind         = gadgetfs_nop,
-       .setup          = (void *)gadgetfs_nop,
-       .disconnect     = gadgetfs_nop,
-       .driver = {
-               .name           = "nop",
-       },
-};
-
-
 /* DEVICE INITIALIZATION
  *
  *     fd = open ("/dev/gadget/$CHIP", O_RDWR)
@@ -1971,9 +1949,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
        if (the_device)
                return -ESRCH;
 
-       /* fake probe to determine $CHIP */
-       CHIP = NULL;
-       usb_gadget_probe_driver(&probe_driver);
+       CHIP = usb_get_gadget_udc_name();
        if (!CHIP)
                return -ENODEV;
 
@@ -2034,6 +2010,8 @@ gadgetfs_kill_sb (struct super_block *sb)
                put_dev (the_device);
                the_device = NULL;
        }
+       kfree(CHIP);
+       CHIP = NULL;
 }
 
 /*----------------------------------------------------------------------*/
index b86a6f03592ec9e1d42f5bdc813b83c1297b6e52..4151597e9d2881ac107012d3cdc895bbcba7dc4f 100644 (file)
@@ -442,6 +442,36 @@ err1:
 }
 EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
 
+/**
+ * usb_get_gadget_udc_name - get the name of the first UDC controller
+ * This functions returns the name of the first UDC controller in the system.
+ * Please note that this interface is usefull only for legacy drivers which
+ * assume that there is only one UDC controller in the system and they need to
+ * get its name before initialization. There is no guarantee that the UDC
+ * of the returned name will be still available, when gadget driver registers
+ * itself.
+ *
+ * Returns pointer to string with UDC controller name on success, NULL
+ * otherwise. Caller should kfree() returned string.
+ */
+char *usb_get_gadget_udc_name(void)
+{
+       struct usb_udc *udc;
+       char *name = NULL;
+
+       /* For now we take the first available UDC */
+       mutex_lock(&udc_lock);
+       list_for_each_entry(udc, &udc_list, list) {
+               if (!udc->driver) {
+                       name = kstrdup(udc->gadget->name, GFP_KERNEL);
+                       break;
+               }
+       }
+       mutex_unlock(&udc_lock);
+       return name;
+}
+EXPORT_SYMBOL_GPL(usb_get_gadget_udc_name);
+
 /**
  * usb_add_gadget_udc - adds a new gadget to the udc class driver list
  * @parent: the parent device to this udc. Usually the controller
index 42527297f2183e9ccda5a8d37368486072409d72..dd7c53279e6ac4835dd999c6c3a088c09ba8365a 100644 (file)
@@ -1136,6 +1136,7 @@ extern int usb_add_gadget_udc_release(struct device *parent,
                struct usb_gadget *gadget, void (*release)(struct device *dev));
 extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
 extern void usb_del_gadget_udc(struct usb_gadget *gadget);
+extern char *usb_get_gadget_udc_name(void);
 
 /*-------------------------------------------------------------------------*/
 
This page took 0.028637 seconds and 5 git commands to generate.