From 53cabad7a225b3607e6920fff50c24016ceec1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 26 Nov 2013 11:31:27 +0100 Subject: fix k8055_takeover_device libusb_detach_kernel_driver() -> LIBUSB_ERROR_NOT_FOUND is not fatal libusb_set_configuration() must be called before libusb_claim_interface() --- libk8055/libk8055.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c index db4ddf3..cea2587 100644 --- a/libk8055/libk8055.c +++ b/libk8055/libk8055.c @@ -215,14 +215,23 @@ static int k8055_takeover_device( struct k8055_dev* dev, int interface ) { memset( driver_name, 0, STR_BUFF ); int ret = K8055_ERROR; assert( handle != NULL ); - if( libusb_detach_kernel_driver( handle, interface )!=0 ) { - if( dev->debug_level>0 ) fprintf( stderr, "usb_detach_kernel_driver fanalog_inputlure\n" ); + int r; + r = libusb_detach_kernel_driver( handle, interface ); + if( r!=0 && r!=LIBUSB_ERROR_NOT_FOUND) { + if( dev->debug_level>0 ) fprintf( stderr, "usb_detach_kernel_driver failure: %d\n", r); + return K8055_ERROR; + } + r = libusb_set_configuration( handle, 1 ); + if ( r!= 0) + { + if( dev->debug_level>0 ) fprintf( stderr, "usb_set_configuration failure: %d\n", r); + return K8055_ERROR; } - if ( libusb_claim_interface( handle, interface )!=0 ) { - if( dev->debug_level>0 ) fprintf( stderr, "usb_claim_interface failure\n" ); + r = libusb_claim_interface( handle, interface ); + if ( r!=0 ) { + if( dev->debug_level>0 ) fprintf( stderr, "usb_claim_interface failure: %d\n", r); return K8055_ERROR; } - libusb_set_configuration( handle, 1 ); if ( dev->debug_level>0 ) fprintf( stderr, "Found interface %d, took over the device\n", interface ); return 0; } -- cgit v1.1-2-g2b99