Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Stanislav Brabec <sbrabec@su...> - 2012-01-04 19:55:59
|
usb_detach_kernel_driver_np() from the compat library returns different error messages than the old libusb0. It causes problems for drivers that expect exact error code. Proposed patch converts libusb1 errors to libusb0 errors. But maybe it is overcomplicated. If we accept that the function was implemented only in Linux (and the same is valid for libusb0), we can just simply return original errno instead of double conversion of errno to libusb1 error code and back to errno. As an alternative, we can check only for -ENODATA condition as libusb-compat does in usb_get_driver_np(). The affected software: lirc-0.8.7/daemons/hw_srm7500libusb.c: srm7500_initialize_usbdongle() The function continues if usb_detach_kernel_driver_np() finishes with no error or if it returns -ENODATA. But the compat layer returns -ENOENT and the driver considers this error as fatal. I am waiting for confirmation of the fix. Downstream bug reference: https://bugzilla.novell.com/show_bug.cgi?id=683307 --- libusb/core.c +++ libusb/core.c @@ -912,6 +912,22 @@ API_EXPORTED int usb_get_driver_np(usb_d API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) { - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + if (r == 0) { + return 0; + } else { + switch (r) { + case LIBUSB_ERROR_NOT_FOUND: + return ENODATA; + case LIBUSB_ERROR_INVALID_PARAM: + return EINVAL; + case LIBUSB_ERROR_NO_DEVICE: + return ENODEV; + case LIBUSB_ERROR_OTHER: + return errno; + default: + return ERANGE; + } + } } -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@... Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ |
From: Xiaofan Chen <xiaofanc@gm...> - 2012-01-05 08:01:37
|
On Thu, Jan 5, 2012 at 3:55 AM, Stanislav Brabec <sbrabec@...> wrote: > usb_detach_kernel_driver_np() from the compat library returns different > error messages than the old libusb0. It causes problems for drivers that > expect exact error code. > > Proposed patch converts libusb1 errors to libusb0 errors. But maybe it > is overcomplicated. If we accept that the function was implemented only > in Linux (and the same is valid for libusb0), we can just simply return > original errno instead of double conversion of errno to libusb1 error > code and back to errno. > > As an alternative, we can check only for -ENODATA condition as > libusb-compat does in usb_get_driver_np(). > > The affected software: > lirc-0.8.7/daemons/hw_srm7500libusb.c: srm7500_initialize_usbdongle() > The function continues if usb_detach_kernel_driver_np() finishes with no > error or if it returns -ENODATA. But the compat layer returns -ENOENT > and the driver considers this error as fatal. > > I am waiting for confirmation of the fix. > Downstream bug reference: > https://bugzilla.novell.com/show_bug.cgi?id=683307 > > --- libusb/core.c > +++ libusb/core.c > @@ -912,6 +912,22 @@ API_EXPORTED int usb_get_driver_np(usb_d > > API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) > { > - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); > + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); > + if (r == 0) { > + return 0; > + } else { > + switch (r) { > + case LIBUSB_ERROR_NOT_FOUND: > + return ENODATA; > + case LIBUSB_ERROR_INVALID_PARAM: > + return EINVAL; > + case LIBUSB_ERROR_NO_DEVICE: > + return ENODEV; > + case LIBUSB_ERROR_OTHER: > + return errno; > + default: > + return ERANGE; > + } > + } > } > > Thanks. I created a ticket for this 20 months ago. So probably you want to add your comments and patch to the ticket. http://www.libusb.org/ticket/42 -- Xiaofan |
From: Peter Stuge <peter@st...> - 2012-01-11 01:42:25
|
Hi Stanislav, Stanislav Brabec wrote: > usb_detach_kernel_driver_np() from the compat library returns different > error messages than the old libusb0. Bad. > Proposed patch converts libusb1 errors to libusb0 errors. But maybe it > is overcomplicated. Thanks. It's mostly fine. > I am waiting for confirmation of the fix. Reading through kernel devio.c and libusb0 linux.c I think the fix is good.. > +++ libusb/core.c > @@ -912,6 +912,22 @@ API_EXPORTED int usb_get_driver_np(usb_d > > API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) > { > - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); > + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); > + if (r == 0) { > + return 0; > + } else { > + switch (r) { ..but please put case 0: inside the switch, instead of the separate if. > + default: > + return ERANGE; And where did this come from? I agree with the other translations, but my kernel devio.c never returns ERANGE? (It would be good to have a libusb-1.0 error for EHOSTUNREACH too, but oh well.) //Peter |
From: Peter Stuge <peter@st...> - 2012-01-11 01:48:42
|
Peter Stuge wrote: > > + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); > > + if (r == 0) { > > + return 0; > > + } else { > > + switch (r) { > > ..but please put case 0: inside the switch, instead of the separate if. Or keep them both, but have the switch after the if, without else. //Peter |
From: Stanislav Brabec <sbrabec@su...> - 2012-02-27 18:34:52
|
On Wed Jan 11, 2012 at 02:42 AM +0100 Peter Stuge wrote: > > + default: > > + return ERANGE; (Sorry for the delay, I overseen your reply.) > And where did this come from? I agree with the other translations, but > my kernel devio.c never returns ERANGE? Well, I supposed it will never be called (= error code out of range). But looking at the libusb-1.0 source code again, we can also get LIBUSB_ERROR_NOT_SUPPORTED on Windows and Darwin. ENOSYS seems to be better. > (It would be good to have a libusb-1.0 error for EHOSTUNREACH too, > but oh well.) op_detach_kernel_driver winn return LIBUSB_ERROR_OTHER and set global variable errno. Wrapper would handle LIBUSB_ERROR_OTHER as return errno, so the calling process will get EHOSTUNREACH. The code can be written without "int r" variable, but I decided to keep r there. It would make debugging easier and the code will be probably optimized into the same binary. >From 4c9f8bcad07a8b9e79a885d9d1d7bc86549cc868 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec <sbrabec@...> Date: Mon, 27 Feb 2012 19:24:23 +0100 Subject: Fix usb_detach_kernel_driver_np() error mapping. usb_detach_kernel_driver_np from the compat library returns different error messages than the old libusb0. It causes problems for drivers that expect exact error code. Convert libusb1 errors to back to libusb0 errors to get 1:1 mapping of kernel error codes. Affected software: lirc-0.8.7/daemons/hw_srm7500libusb.c: srm7500_initialize_usbdongle() The function continues if usb_detach_kernel_driver_np() finishes with no error or if it returns -ENODATA. But the compat layer returns -ENOENT and the driver considers this error as fatal. Downstream bug reference: https://bugzilla.novell.com/show_bug.cgi?id=683307 --- libusb/core.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index 04b1822..e26f21b 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -916,6 +916,22 @@ API_EXPORTED int usb_get_driver_np(usb_dev_handle *dev, int interface, API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) { - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + switch (r) { + case LIBUSB_SUCCESS: + return 0; + case LIBUSB_ERROR_NOT_FOUND: + return ENODATA; + case LIBUSB_ERROR_INVALID_PARAM: + return EINVAL; + case LIBUSB_ERROR_NO_DEVICE: + return ENODEV; + case LIBUSB_ERROR_OTHER: + return errno; + /* default can be reached in libusb-1.0 only in non-Linux implementations, + * mostly with LIBUSB_ERROR_NOT_SUPPORTED. */ + default: + return ENOSYS; + } } -- 1.7.7 -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@... Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ |
From: Stanislav Brabec <sbrabec@su...> - 2012-04-03 17:58:24
|
On Mon Feb 27, 2012 at 07:34 PM +0100 Stanislav Brabec wrote: >The code can be written without "int r" variable, but I decided to keep >r there. It would make debugging easier and the code will be probably >optimized into the same binary. I just found one bug in the code - libusb0 returns -errno, not errno. If LIBUSB_ERROR_OTHER occurs, my code depends on errno kept. Looking at the Linux code of libusb1, only usbi_err can alter it. Adding a small test, that verifies that errno should be kept there. /* gcc -Wall test.c core.o -I. -o test -lusb-1.0 ; LIBUSB_DEBUG=255 ./test */ #include <stdio.h> #include <errno.h> #include <string.h> #include <unistd.h> #include "libusbi.h" int main (void) { struct libusb_device_handle handle; struct libusb_device_handle *handle_p = &handle; access("/file_that_does_not_exist", W_OK); usbi_err(HANDLE_CTX(handle_p), "detach failed error %d errno %d", -1, errno); printf("error should be ENOENT: %s\n", strerror (errno)); access("/", W_OK); usbi_err(HANDLE_CTX(handle_p), "detach failed error %d errno %d", -1, errno); printf("error should be EPERM: %s\n", strerror (errno)); return 0; } usb_detach_kernel_driver_np() from the compat library returns different error messages than the old libusb0. It causes problems for drivers that expect exact error code. Proposed patch converts libusb1 errors to libusb0 errors. But maybe it is overcomplicated. If we accept that the function was implemented only in Linux (and the same is valid for libusb0), we can just simply return original errno instead of double conversion of errno to libusb1 error code and back to errno. As an alternative, we can check only for -ENODATA condition as libusb-compat does in usb_get_driver_np(). The affected software: lirc-0.8.7/daemons/hw_srm7500libusb.c: srm7500_initialize_usbdongle() The function continues if usb_detach_kernel_driver_np() finishes with no error or if it returns -ENODATA. But the compat layer returns -ENOENT and the driver considers this error as fatal. I am waiting for confirmation of the fix. Upstream bug reference: http://www.libusb.org/ticket/42 Downstream bug reference: https://bugzilla.novell.com/show_bug.cgi?id=683307 --- libusb/core.c +++ libusb/core.c @@ -912,6 +912,22 @@ API_EXPORTED int usb_get_driver_np(usb_d API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) { - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + if (r == 0) { + return 0; + } else { + switch (r) { + case LIBUSB_ERROR_NOT_FOUND: + return ENODATA; + case LIBUSB_ERROR_INVALID_PARAM: + return EINVAL; + case LIBUSB_ERROR_NO_DEVICE: + return ENODEV; + case LIBUSB_ERROR_OTHER: + return -errno; + default: + return ERANGE; + } + } } -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@... Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ |
From: Stanislav Brabec <sbrabec@su...> - 2012-04-03 18:05:58
|
OOPS. Bad patch attached. Here is the correct one: >From 4c9f8bcad07a8b9e79a885d9d1d7bc86549cc868 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec <sbrabec@...> Date: Tue Apr 3 20:03:20 CEST 2012 Subject: Fix usb_detach_kernel_driver_np() error mapping. usb_detach_kernel_driver_np from the compat library returns different error messages than the old libusb0. It causes problems for drivers that expect exact error code. Convert libusb1 errors to back to libusb0 errors to get 1:1 mapping of kernel error codes. Affected software: lirc-0.8.7/daemons/hw_srm7500libusb.c: srm7500_initialize_usbdongle() The function continues if usb_detach_kernel_driver_np() finishes with no error or if it returns -ENODATA. But the compat layer returns -ENOENT and the driver considers this error as fatal. Upstream bug reference: http://www.libusb.org/ticket/42 Downstream bug reference: https://bugzilla.novell.com/show_bug.cgi?id=683307 --- libusb/core.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index 04b1822..e26f21b 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -916,6 +916,22 @@ API_EXPORTED int usb_get_driver_np(usb_dev_handle *dev, int interface, API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) { - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + switch (r) { + case LIBUSB_SUCCESS: + return 0; + case LIBUSB_ERROR_NOT_FOUND: + return ENODATA; + case LIBUSB_ERROR_INVALID_PARAM: + return EINVAL; + case LIBUSB_ERROR_NO_DEVICE: + return ENODEV; + case LIBUSB_ERROR_OTHER: + return -errno; + /* default can be reached in libusb-1.0 only in non-Linux implementations, + * mostly with LIBUSB_ERROR_NOT_SUPPORTED. */ + default: + return ENOSYS; + } } -- 1.7.7 -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@... Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ |
From: Stanislav Brabec <sbrabec@su...> - 2012-04-04 15:47:23
|
Stanislav Brabec wrote: > OOPS. Bad patch attached. Here is the correct one: Sorry for spamming, but comparing libusb0 and libusb1 codes again, I see that libusb0 should return negative number on all error conditions, but error code defines are positive numbers. New patch fixes sign of all error codes. I hope that this patch is really the last one and it interprets all error codes correctly. >From 4c9f8bcad07a8b9e79a885d9d1d7bc86549cc868 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec <sbrabec@...> Date: Wed Apr 4 17:44:24 CEST 2012 Subject: Fix usb_detach_kernel_driver_np() error mapping. usb_detach_kernel_driver_np from the compat library returns different error messages than the old libusb0. It causes problems for drivers that expect exact error code. Convert libusb1 errors to back to libusb0 errors to get 1:1 mapping of kernel error codes. Affected software: lirc-0.8.7/daemons/hw_srm7500libusb.c: srm7500_initialize_usbdongle() The function continues if usb_detach_kernel_driver_np() finishes with no error or if it returns -ENODATA. But the compat layer returns -ENOENT and the driver considers this error as fatal. Upstream bug reference: http://www.libusb.org/ticket/42 Upstream mailing list reference: http://sourceforge.net/mailarchive/forum.php?thread_name=1325706952.5095.49.camel%40oct.suse.cz&forum_name=libusb-devel Downstream bug reference: https://bugzilla.novell.com/show_bug.cgi?id=683307 --- libusb/core.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index 04b1822..e26f21b 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -916,6 +916,22 @@ API_EXPORTED int usb_get_driver_np(usb_dev_handle *dev, int interface, API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface) { - return compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + int r = compat_err(libusb_detach_kernel_driver(dev->handle, interface)); + switch (r) { + case LIBUSB_SUCCESS: + return 0; + case LIBUSB_ERROR_NOT_FOUND: + return -ENODATA; + case LIBUSB_ERROR_INVALID_PARAM: + return -EINVAL; + case LIBUSB_ERROR_NO_DEVICE: + return -ENODEV; + case LIBUSB_ERROR_OTHER: + return -errno; + /* default can be reached in libusb-1.0 only in non-Linux implementations, + * mostly with LIBUSB_ERROR_NOT_SUPPORTED. */ + default: + return -ENOSYS; + } } -- 1.7.7 -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@... Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ |
From: Xiaofan Chen <xiaofanc@gm...> - 2012-04-07 01:19:39
|
On Wed, Apr 4, 2012 at 11:47 PM, Stanislav Brabec <sbrabec@...> wrote: > Stanislav Brabec wrote: >> OOPS. Bad patch attached. Here is the correct one: > > Sorry for spamming, but comparing libusb0 and libusb1 codes again, I see > that libusb0 should return negative number on all error conditions, but > error code defines are positive numbers. New patch fixes sign of all > error codes. I hope that this patch is really the last one and it > interprets all error codes correctly. Thanks. Looks good to me. -- Xiaofan |