From: Michael Gernoth Date: Sat, 12 Apr 2008 13:13:26 +0000 (+0200) Subject: make it possible to return an error everywhere X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/commitdiff_plain/8af4d9103d2006a929cf9048835a4dcfcf6e344d make it possible to return an error everywhere --- diff --git a/usb-driver.c b/usb-driver.c index 0383d12..b4d3414 100644 --- a/usb-driver.c +++ b/usb-driver.c @@ -156,7 +156,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_transfer(xpcu, ut); + ret = xpcu_transfer(xpcu, ut); #endif #ifdef DEBUG @@ -184,7 +184,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_int_state(xpcu, it, ENABLE_INTERRUPT); + ret = xpcu_int_state(xpcu, it, ENABLE_INTERRUPT); #endif DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", @@ -207,7 +207,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_int_state(xpcu, it, DISABLE_INTERRUPT); + ret = xpcu_int_state(xpcu, it, DISABLE_INTERRUPT); #endif DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, @@ -227,7 +227,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_set_interface(xpcu, usi); + ret = xpcu_set_interface(xpcu, usi); #endif DPRINTF("<- unique: 0x%lx, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, @@ -245,7 +245,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions); - ugdd->dwBytes = xpcu_deviceinfo(xpcu, ugdd); + ret = xpcu_deviceinfo(xpcu, ugdd); } break; @@ -333,7 +333,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_close(xpcu, e); + ret = xpcu_close(xpcu, e); #endif } break; @@ -351,7 +351,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_int_wait(xpcu, it); + ret = xpcu_int_wait(xpcu, it); #endif DPRINTF("<- INT_WAIT_RETURN: Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", @@ -413,7 +413,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { #ifndef NO_WINDRVR ret = (*ioctl_func) (fd, request, wdioctl); #else - xpcu_found(xpcu, e); + ret = xpcu_found(xpcu, e); #endif #ifdef DEBUG diff --git a/xpcu.c b/xpcu.c index 9cea2c1..719829b 100644 --- a/xpcu.c +++ b/xpcu.c @@ -21,6 +21,9 @@ int xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd) { if (ugdd->dwUniqueID != (unsigned long)xpcu) return -ENODEV; + + if (!xpcu) + return -ENODEV; if (ugdd->dwBytes) buf = ugdd->pBuf; @@ -176,7 +179,9 @@ int xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd) { } } - return len; + ugdd->dwBytes = len; + + return 0; } static int xpcu_claim(struct xpcu_s *xpcu, int claim) { @@ -217,6 +222,9 @@ int xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut) { if (ut->dwUniqueID != (unsigned long)xpcu) return -ENODEV; + + if (!xpcu) + return -ENODEV; xpcu_claim(xpcu, XPCU_CLAIM); /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */ @@ -248,9 +256,12 @@ int xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut) { return ret; } -void xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi) { +int xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi) { if (usi->dwUniqueID != (unsigned long)xpcu) - return; + return -ENODEV; + + if (!xpcu) + return -ENODEV; if (xpcu->dev) { if (!xpcu->handle) { @@ -266,6 +277,8 @@ void xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi) { xpcu->interface = xpcu->dev->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber; xpcu->alternate = usi->dwAlternateSetting; } + + return 0; } static void xpcu_init(void) { @@ -385,7 +398,7 @@ struct xpcu_s *xpcu_find(struct event *e) { return &xpcu; } -void xpcu_found(struct xpcu_s *xpcu, struct event *e) { +int xpcu_found(struct xpcu_s *xpcu, struct event *e) { if (e->handle && e->handle == (unsigned long)xpcu && xpcu->dev) { struct usb_interface *interface = xpcu->dev->config->interface; @@ -401,11 +414,16 @@ void xpcu_found(struct xpcu_s *xpcu, struct event *e) { e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass; e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol; } + + return 0; } -void xpcu_close(struct xpcu_s *xpcu, struct event *e) { +int xpcu_close(struct xpcu_s *xpcu, struct event *e) { if (e->handle != (unsigned long)xpcu) - return; + return -ENODEV; + + if (!xpcu) + return -ENODEV; if(xpcu) { if (xpcu->handle) { @@ -418,13 +436,15 @@ void xpcu_close(struct xpcu_s *xpcu, struct event *e) { xpcu->alternate = -1; busses = NULL; } + + return 0; } -void xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable) { +int xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable) { static pthread_mutex_t *interrupt = &dummy_interrupt; if (it->hInterrupt != (unsigned long)xpcu) - return; + return -ENODEV; if (xpcu) interrupt = &xpcu->interrupt; @@ -439,11 +459,13 @@ void xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable) { if (pthread_mutex_trylock(interrupt) == EBUSY) pthread_mutex_unlock(interrupt); } + + return 0; } -void xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it) { +int xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it) { if (it->hInterrupt != (unsigned long)xpcu) - return; + return -ENODEV; if (xpcu) { if (it->dwCounter == 0) { @@ -456,4 +478,6 @@ void xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it) { pthread_mutex_lock(&dummy_interrupt); pthread_mutex_unlock(&dummy_interrupt); } + + return 0; } diff --git a/xpcu.h b/xpcu.h index cde1421..30ff4f1 100644 --- a/xpcu.h +++ b/xpcu.h @@ -15,9 +15,9 @@ struct xpcu_s { int __attribute__ ((visibility ("hidden"))) xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd); int __attribute__ ((visibility ("hidden"))) xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut); -void __attribute__ ((visibility ("hidden"))) xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi); +int __attribute__ ((visibility ("hidden"))) xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi); struct xpcu_s __attribute__ ((visibility ("hidden"))) *xpcu_find(struct event *e); -void __attribute__ ((visibility ("hidden"))) xpcu_found(struct xpcu_s *xpcu, struct event *e); -void __attribute__ ((visibility ("hidden"))) xpcu_close(struct xpcu_s *xpcu, struct event *e); -void __attribute__ ((visibility ("hidden"))) xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable); -void __attribute__ ((visibility ("hidden"))) xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it); +int __attribute__ ((visibility ("hidden"))) xpcu_found(struct xpcu_s *xpcu, struct event *e); +int __attribute__ ((visibility ("hidden"))) xpcu_close(struct xpcu_s *xpcu, struct event *e); +int __attribute__ ((visibility ("hidden"))) xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable); +int __attribute__ ((visibility ("hidden"))) xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it);