aboutsummaryrefslogtreecommitdiff
path: root/common/usb.c
diff options
context:
space:
mode:
authorSimon Glass2015-03-25 12:22:01 -0600
committerSimon Glass2015-04-18 11:11:20 -0600
commit79b5888729b65e7040d6a964f0015fc2c21b2385 (patch)
tree3497e7a22e622a32b7f3257682456087b17e409c /common/usb.c
parentcad4291cd053f8eaa404e47ab289a6169c19ae93 (diff)
dm: usb: Adjust usb_alloc_new_device() to return an error
This function returns NULL on error at present. Adjust it so that we can return a real error, as is needed with driver model. Also improve the error handling in its caller, usb_hub_port_connect_change(), and adjust the code order to prepare for driver model. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'common/usb.c')
-rw-r--r--common/usb.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/common/usb.c b/common/usb.c
index d94640a99e8..4f3713d92f3 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -94,8 +94,8 @@ int usb_init(void)
controllers_initialized++;
start_index = dev_index;
printf("scanning bus %d for devices... ", i);
- dev = usb_alloc_new_device(ctrl);
- if (!dev)
+ ret = usb_alloc_new_device(ctrl, &dev);
+ if (ret)
break;
/*
@@ -104,7 +104,7 @@ int usb_init(void)
*/
ret = usb_new_device(dev);
if (ret)
- usb_free_device();
+ usb_free_device(dev->controller);
if (start_index == dev_index) {
puts("No USB Device found\n");
@@ -833,16 +833,13 @@ struct usb_device *usb_get_dev_index(int index)
return &usb_dev[index];
}
-/* returns a pointer of a new device structure or NULL, if
- * no device struct is available
- */
-struct usb_device *usb_alloc_new_device(void *controller)
+int usb_alloc_new_device(struct udevice *controller, struct usb_device **devp)
{
int i;
debug("New Device %d\n", dev_index);
if (dev_index == USB_MAX_DEVICE) {
printf("ERROR, too many USB Devices, max=%d\n", USB_MAX_DEVICE);
- return NULL;
+ return -ENOSPC;
}
/* default Address is 0, real addresses start with 1 */
usb_dev[dev_index].devnum = dev_index + 1;
@@ -852,7 +849,9 @@ struct usb_device *usb_alloc_new_device(void *controller)
usb_dev[dev_index].parent = NULL;
usb_dev[dev_index].controller = controller;
dev_index++;
- return &usb_dev[dev_index - 1];
+ *devp = &usb_dev[dev_index - 1];
+
+ return 0;
}
/*
@@ -860,7 +859,7 @@ struct usb_device *usb_alloc_new_device(void *controller)
* Called in error cases where configuring a newly attached
* device fails for some reason.
*/
-void usb_free_device(void)
+void usb_free_device(struct udevice *controller)
{
dev_index--;
debug("Freeing device node: %d\n", dev_index);