diff options
author | Benoit Goby <benoitgoby@google.com> | 2014-01-28 00:07:15 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-01-28 00:07:15 +0000 |
commit | 6ddabb7a1cc3080ae773acb045f69b5e6afee87a (patch) | |
tree | 336b0847ce6a5a66146409bd16df0dd4b19cad23 | |
parent | 6bfb7b64ba857f78c0a0bcb08591003655df2b7e (diff) | |
parent | 4cbf1d882236462482b8e22893061604b224e308 (diff) | |
download | system_core-6ddabb7a1cc3080ae773acb045f69b5e6afee87a.zip system_core-6ddabb7a1cc3080ae773acb045f69b5e6afee87a.tar.gz system_core-6ddabb7a1cc3080ae773acb045f69b5e6afee87a.tar.bz2 |
Merge "adbd: Don't close/reopen FFS ep0 on disconnect"
-rw-r--r-- | adb/usb_linux_client.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c index 69d8062..8426e0e 100644 --- a/adb/usb_linux_client.c +++ b/adb/usb_linux_client.c @@ -264,23 +264,25 @@ static void init_functionfs(struct usb_handle *h) { ssize_t ret; - D("OPENING %s\n", USB_FFS_ADB_EP0); - h->control = adb_open(USB_FFS_ADB_EP0, O_RDWR); - if (h->control < 0) { - D("[ %s: cannot open control endpoint: errno=%d]\n", USB_FFS_ADB_EP0, errno); - goto err; - } + if (h->control < 0) { // might have already done this before + D("OPENING %s\n", USB_FFS_ADB_EP0); + h->control = adb_open(USB_FFS_ADB_EP0, O_RDWR); + if (h->control < 0) { + D("[ %s: cannot open control endpoint: errno=%d]\n", USB_FFS_ADB_EP0, errno); + goto err; + } - ret = adb_write(h->control, &descriptors, sizeof(descriptors)); - if (ret < 0) { - D("[ %s: write descriptors failed: errno=%d ]\n", USB_FFS_ADB_EP0, errno); - goto err; - } + ret = adb_write(h->control, &descriptors, sizeof(descriptors)); + if (ret < 0) { + D("[ %s: write descriptors failed: errno=%d ]\n", USB_FFS_ADB_EP0, errno); + goto err; + } - ret = adb_write(h->control, &strings, sizeof(strings)); - if (ret < 0) { - D("[ %s: writing strings failed: errno=%d]\n", USB_FFS_ADB_EP0, errno); - goto err; + ret = adb_write(h->control, &strings, sizeof(strings)); + if (ret < 0) { + D("[ %s: writing strings failed: errno=%d]\n", USB_FFS_ADB_EP0, errno); + goto err; + } } h->bulk_out = adb_open(USB_FFS_ADB_OUT, O_RDWR); @@ -320,14 +322,14 @@ static void *usb_ffs_open_thread(void *x) while (1) { // wait until the USB device needs opening adb_mutex_lock(&usb->lock); - while (usb->control != -1) + while (usb->control != -1 && usb->bulk_in != -1 && usb->bulk_out != -1) adb_cond_wait(&usb->notify, &usb->lock); adb_mutex_unlock(&usb->lock); while (1) { init_functionfs(usb); - if (usb->control >= 0) + if (usb->control >= 0 && usb->bulk_in >= 0 && usb->bulk_out >= 0) break; adb_sleep_ms(1000); @@ -424,10 +426,13 @@ static void usb_ffs_kick(usb_handle *h) D("[ kick: sink (fd=%d) clear halt failed (%d) ]", h->bulk_out, errno); adb_mutex_lock(&h->lock); - adb_close(h->control); + + // don't close ep0 here, since we may not need to reinitialize it with + // the same descriptors again. if however ep1/ep2 fail to re-open in + // init_functionfs, only then would we close and open ep0 again. adb_close(h->bulk_out); adb_close(h->bulk_in); - h->control = h->bulk_out = h->bulk_in = -1; + h->bulk_out = h->bulk_in = -1; // notify usb_ffs_open_thread that we are disconnected adb_cond_signal(&h->notify); |