libftdi Archives

Subject: Re: (Corrected)In linusb-1.0, libusb_detach_kernel_driver is available unconditional

From: Xiaofan Chen <xiaofanc@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 18 May 2010 21:50:11 +0800
On Tue, May 18, 2010 at 9:35 PM, Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> What about appended patch:
>
> Unconditionally call usb_detach_kernel_driver. Check the return value only
> later when other things fail, caused perhaps by missing permissions.
>

> -#ifdef LIBUSB_HAS_GET_DRIVER_NP

This is of course right.

>     // Try to detach ftdi_sio kernel module.
> -    // Returns ENODATA if driver is not loaded.

Again correct.

>     //
>     // The return code is kept in a separate variable and only parsed
>     // if usb_set_configuration() or usb_claim_interface() fails as the
>     // detach operation might be denied and everything still works fine.
>     // Likely scenario is a static ftdi_sio kernel module.
> -    ret = libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface);
> -    if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND)
> -        ftdi_error_return(-11, "libusb_detach_kernel_driver () failed");
> -#endif

> +    detach_errno = libusb_detach_kernel_driver(ftdi->usb_dev, 
> ftdi->interface);
>

> @@ -482,14 +476,28 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, 
> libusb_device *dev)
>         if (libusb_set_configuration(ftdi->usb_dev, cfg0) < 0)
>         {
>             ftdi_usb_close_internal (ftdi);
> -            ftdi_error_return(-3, "unable to set usb configuration. Make 
> sure ftdi_sio is unloaded!");
> +            if(detach_errno == EPERM)
> +            {
> +                ftdi_error_return(-8, "inappropriate permissions on 
> device!");
> +            }
> +            else
> +            {
> +                ftdi_error_return(-3, "unable to set usb configuration. Make 
> sure ftdi_sio is unloaded!");
> +            }

As mentioned before, libftdi-1.0 should not return error if the
detach_errorno is LIBUSB_NOT_FOUND (Linux, kernel driver already detached)
or LIBUSB_NOT_SUPPORTED (Windows and Mac OS X/Darwin).


-- 
Xiaofan http://mcuee.blogspot.com

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread