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 20:23:08 +0800
On Tue, May 18, 2010 at 8:13 PM, Thomas Jarosch
<thomas.jarosch@xxxxxxxxxxxxx> wrote:
> On Tuesday, 18. May 2010 13:43:53 Xiaofan Chen wrote:
>> That is exactly right. And I think failure to detach the kernel driver is
>> quite normal (eg: you already run libftdi once and the kernel driver
>> is already detached) and should not return error. A warning is enough.
>>     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");
> That's the reason we already ignore LIBUSB_ERROR_NOT_FOUND ;) I never had
> trouble with the detach code. If the detach really fails
> (except _NOT_FOUND and _NOT_SUPPORTED), then we should abort with an error.

You are probably right. The above patch is not really right though since
it does not ignore LIBUSB_NOT_SUPPORTED (Darwin/Windows libusb-1.0
will return this error code).

Take note that the return codes can be others under Linux. But I believe
you are right that ENODATA (for libusb-0.1) and
LIBUSB_ERROR_NOT_FOUND (for libusb-1.0) are not real errors.
The other three situation are probably real errors.

>From libusb-1.0 linux_usbfs.c:

static int op_detach_kernel_driver(struct libusb_device_handle *handle,
        int interface)
        int fd = __device_handle_priv(handle)->fd;
        struct usbfs_ioctl command;
        int r;

        command.ifno = interface;
        command.ioctl_code = IOCTL_USBFS_DISCONNECT; = NULL;

        r = ioctl(fd, IOCTL_USBFS_IOCTL, &command);
        if (r) {
                if (errno == ENODATA)
                        return LIBUSB_ERROR_NOT_FOUND;
                else if (errno == EINVAL)
                        return LIBUSB_ERROR_INVALID_PARAM;
                else if (errno == ENODEV)
                        return LIBUSB_ERROR_NO_DEVICE;

                        "detach failed error %d errno %d", r, errno);
                return LIBUSB_ERROR_OTHER;

        return 0;


libftdi - see for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread