Commit f1bddbb3 authored by Krzysztof Opasiak's avatar Krzysztof Opasiak Committed by Felipe Balbi

usb: gadget: Fix binding to UDC via configfs interface

By default user could store only valid UDC name in configfs UDC
attr by doing:

echo $UDC_NAME > UDC

Commit (855ed04a "usb: gadget: udc-core: independent registration of
gadgets and gadget drivers") broke this behavior and allowed to store
any arbitrary string in UDC file and udc core was waiting for such
controller to appear.

echo "any arbitrary string here" > UDC

This commit fix this by adding a flag which prevents configfs
gadget from being added to list of pending drivers if UDC with
given name has not been found.
Signed-off-by: default avatarKrzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 1a695a90
...@@ -1401,6 +1401,7 @@ static const struct usb_gadget_driver configfs_driver_template = { ...@@ -1401,6 +1401,7 @@ static const struct usb_gadget_driver configfs_driver_template = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "configfs-gadget", .name = "configfs-gadget",
}, },
.match_existing_only = 1,
}; };
static struct config_group *gadgets_make( static struct config_group *gadgets_make(
......
...@@ -603,11 +603,15 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) ...@@ -603,11 +603,15 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
} }
} }
if (!driver->match_existing_only) {
list_add_tail(&driver->pending, &gadget_driver_pending_list); list_add_tail(&driver->pending, &gadget_driver_pending_list);
pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n", pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n",
driver->function); driver->function);
ret = 0;
}
mutex_unlock(&udc_lock); mutex_unlock(&udc_lock);
return 0; return ret;
found: found:
ret = udc_bind_to_driver(udc, driver); ret = udc_bind_to_driver(udc, driver);
mutex_unlock(&udc_lock); mutex_unlock(&udc_lock);
......
...@@ -1034,6 +1034,8 @@ static inline int usb_gadget_activate(struct usb_gadget *gadget) ...@@ -1034,6 +1034,8 @@ static inline int usb_gadget_activate(struct usb_gadget *gadget)
* @udc_name: A name of UDC this driver should be bound to. If udc_name is NULL, * @udc_name: A name of UDC this driver should be bound to. If udc_name is NULL,
* this driver will be bound to any available UDC. * this driver will be bound to any available UDC.
* @pending: UDC core private data used for deferred probe of this driver. * @pending: UDC core private data used for deferred probe of this driver.
* @match_existing_only: If udc is not found, return an error and don't add this
* gadget driver to list of pending driver
* *
* Devices are disabled till a gadget driver successfully bind()s, which * Devices are disabled till a gadget driver successfully bind()s, which
* means the driver will handle setup() requests needed to enumerate (and * means the driver will handle setup() requests needed to enumerate (and
...@@ -1097,6 +1099,7 @@ struct usb_gadget_driver { ...@@ -1097,6 +1099,7 @@ struct usb_gadget_driver {
char *udc_name; char *udc_name;
struct list_head pending; struct list_head pending;
unsigned match_existing_only:1;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment