usb: udc: Try to clarify an error message

At some point when trying to use USB gadgets, two situations may arise
and lead to a failure. Either the UDC (USB Device Controller) is not
available at all (not described or not probed) or the UDC is already in
use. For instance, as the USB Ethernet gadget remains bound to the UDC,
the use of any other USB gadget (fastboot, dfu, etc) *after* will always
fail with the "couldn't find an available UDC" error.

Let's give a more helpful message by making a difference between the two
cases. Let's also hint people who would get this error and grep it into
the sources a better explanation of what's wrong with their workflow.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Link: https://lore.kernel.org/r/20231010090304.49335-4-miquel.raynal@bootlin.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
This commit is contained in:
Miquel Raynal 2023-10-10 11:03:04 +02:00 committed by Mattijs Korpershoek
parent 249a75d8e8
commit 8a0d07807a

View file

@ -323,6 +323,7 @@ err1:
int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
{
struct usb_udc *udc = NULL;
unsigned int udc_count = 0;
int ret;
if (!driver || !driver->bind || !driver->setup)
@ -330,12 +331,22 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
mutex_lock(&udc_lock);
list_for_each_entry(udc, &udc_list, list) {
udc_count++;
/* For now we take the first one */
if (!udc->driver)
goto found;
}
printf("couldn't find an available UDC\n");
if (!udc_count)
printf("No UDC available in the system\n");
else
/* When this happens, users should 'unbind <class> <index>'
* using the output of 'dm tree' and looking at the line right
* after the USB peripheral/device controller.
*/
printf("All UDCs in use (%d available), use the unbind command\n",
udc_count);
mutex_unlock(&udc_lock);
return -ENODEV;
found: