Skip to content

Commit 2b2bb76

Browse files
committed
usb: Reattach kernel driver on close
This releases the usb interface and restores the kernel driver that was detached when opening the device. This allows other programs to make use of the tty device when qdl finishes. Signed-off-by: Jerry Zhang <[email protected]>
1 parent b4030fa commit 2b2bb76

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

usb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct qdl_device_usb {
2020

2121
int in_ep;
2222
int out_ep;
23+
int intf;
2324

2425
size_t in_maxpktsize;
2526
size_t out_maxpktsize;
@@ -156,6 +157,7 @@ static int usb_try_open(libusb_device *dev, struct qdl_device_usb *qdl, const ch
156157
qdl->usb_handle = handle;
157158
qdl->in_ep = in;
158159
qdl->out_ep = out;
160+
qdl->intf = ifc->bInterfaceNumber;
159161
qdl->in_maxpktsize = in_size;
160162
qdl->out_maxpktsize = out_size;
161163

@@ -227,6 +229,8 @@ static void usb_close(struct qdl_device *qdl)
227229
{
228230
struct qdl_device_usb *qdl_usb = container_of(qdl, struct qdl_device_usb, base);
229231

232+
libusb_release_interface(qdl_usb->usb_handle, qdl_usb->intf);
233+
libusb_attach_kernel_driver(qdl_usb->usb_handle, qdl_usb->intf);
230234
libusb_close(qdl_usb->usb_handle);
231235
libusb_exit(NULL);
232236
}

0 commit comments

Comments
 (0)