binding a device driver could fail.. handle this case

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14493 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Christian Gmeiner 2007-08-28 20:50:41 +00:00
parent 195ef597f5
commit 4474d6827c
6 changed files with 19 additions and 11 deletions

View file

@ -378,6 +378,8 @@ static void update_driver_names(unsigned char* result) {
static void bind_device_driver(struct usb_device_driver* driver) { static void bind_device_driver(struct usb_device_driver* driver) {
int ret = 0;
/* look if there is an old driver */ /* look if there is an old driver */
if (usbcore.active_controller->device_driver != NULL) { if (usbcore.active_controller->device_driver != NULL) {
usbcore.active_controller->device_driver->unbind(); usbcore.active_controller->device_driver->unbind();
@ -387,7 +389,11 @@ static void bind_device_driver(struct usb_device_driver* driver) {
usbcore.active_controller->device_driver = driver; usbcore.active_controller->device_driver = driver;
/* init dirver */ /* init dirver */
driver->bind(usbcore.active_controller->controller_ops); ret = driver->bind(usbcore.active_controller->controller_ops);
if (ret != 0) {
logf("binding of %s failed", driver->name);
usbcore.active_controller->device_driver = NULL;
usbcore.device_driver = NULL;
}
} }

View file

@ -25,7 +25,7 @@
*/ */
struct usb_device_driver { struct usb_device_driver {
const char* name; const char* name;
void (*bind)(void* controller_ops); int (*bind)(void* controller_ops);
void (*unbind)(void); void (*unbind)(void);
int (*request)(struct usb_ctrlrequest* req); int (*request)(struct usb_ctrlrequest* req);
void (*suspend)(void); void (*suspend)(void);

View file

@ -169,7 +169,7 @@ void usb_serial_driver_init(void)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
void usb_serial_driver_bind(void* controler_ops) int usb_serial_driver_bind(void* controler_ops)
{ {
logf("usb serial: bind"); logf("usb serial: bind");
ops = controler_ops; ops = controler_ops;
@ -201,10 +201,11 @@ void usb_serial_driver_bind(void* controler_ops)
serial_debug_desc.bDebugInEndpoint = dev.in->ep_num; serial_debug_desc.bDebugInEndpoint = dev.in->ep_num;
serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num; serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num;
return; return 0;
autoconf_fail: autoconf_fail:
logf("failed to find endpoints"); logf("failed to find endpoints");
return -EOPNOTSUPP;
} }
int usb_serial_driver_request(struct usb_ctrlrequest* request) int usb_serial_driver_request(struct usb_ctrlrequest* request)

View file

@ -25,7 +25,7 @@
/* register serial driver in usb stack */ /* register serial driver in usb stack */
void usb_serial_driver_init(void); void usb_serial_driver_init(void);
void usb_serial_driver_bind(void* controller_ops); int usb_serial_driver_bind(void* controller_ops);
int usb_serial_driver_request(struct usb_ctrlrequest* req); int usb_serial_driver_request(struct usb_ctrlrequest* req);
void usb_serial_driver_speed(enum usb_device_speed speed); void usb_serial_driver_speed(enum usb_device_speed speed);

View file

@ -160,7 +160,7 @@ void usb_storage_driver_init(void)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* device driver ops */ /* device driver ops */
void usb_storage_driver_bind(void* controler_ops) int usb_storage_driver_bind(void* controler_ops)
{ {
ops = controler_ops; ops = controler_ops;
@ -181,10 +181,11 @@ void usb_storage_driver_bind(void* controler_ops)
dev.out->claimed = true; dev.out->claimed = true;
logf("usb storage: out: %s", dev.out->name); logf("usb storage: out: %s", dev.out->name);
return; return 0;
autoconf_fail: autoconf_fail:
logf("failed to find endpoints"); logf("failed to find endpoints");
return -EOPNOTSUPP;
} }
int usb_storage_driver_request(struct usb_ctrlrequest* request) int usb_storage_driver_request(struct usb_ctrlrequest* request)

View file

@ -22,10 +22,10 @@
#include "usbstack/core.h" #include "usbstack/core.h"
/* register serial driver in usb stack */ /* register storage driver in usb stack */
void usb_storage_driver_init(void); void usb_storage_driver_init(void);
void usb_storage_driver_bind(void* controller_ops); int usb_storage_driver_bind(void* controller_ops);
int usb_storage_driver_request(struct usb_ctrlrequest* req); int usb_storage_driver_request(struct usb_ctrlrequest* req);
void usb_storage_driver_speed(enum usb_device_speed speed); void usb_storage_driver_speed(enum usb_device_speed speed);