Loading adb/daemon/usb.cpp +2 −31 Original line number Diff line number Diff line Loading @@ -58,10 +58,6 @@ using namespace std::chrono_literals; #define cpu_to_le16(x) htole16(x) #define cpu_to_le32(x) htole32(x) #define FUNCTIONFS_ENDPOINT_ALLOC _IOR('g', 231, __u32) static constexpr size_t ENDPOINT_ALLOC_RETRIES = 10; static int dummy_fd = -1; struct func_desc { Loading Loading @@ -256,7 +252,6 @@ bool init_functionfs(struct usb_handle* h) { ssize_t ret; struct desc_v1 v1_descriptor; struct desc_v2 v2_descriptor; size_t retries = 0; v2_descriptor.header.magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2); v2_descriptor.header.length = cpu_to_le32(sizeof(v2_descriptor)); Loading Loading @@ -326,30 +321,6 @@ bool init_functionfs(struct usb_handle* h) { h->read_aiob.fd = h->bulk_out; h->write_aiob.fd = h->bulk_in; h->max_rw = MAX_PAYLOAD; while (h->max_rw >= USB_FFS_BULK_SIZE && retries < ENDPOINT_ALLOC_RETRIES) { int ret_in = ioctl(h->bulk_in, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(h->max_rw)); int errno_in = errno; int ret_out = ioctl(h->bulk_out, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(h->max_rw)); int errno_out = errno; if (ret_in || ret_out) { if (errno_in == ENODEV || errno_out == ENODEV) { std::this_thread::sleep_for(100ms); retries += 1; continue; } h->max_rw /= 2; } else { return true; } } D("[ adb: cannot call endpoint alloc: errno=%d ]", errno); // Kernel pre-allocation could have failed for recoverable reasons. // Continue running with a safe max rw size. h->max_rw = USB_FFS_BULK_SIZE; return true; err: Loading Loading @@ -403,7 +374,7 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len) { const char* buf = static_cast<const char*>(data); while (len > 0) { int write_len = std::min(h->max_rw, len); int write_len = std::min(USB_FFS_BULK_SIZE, len); int n = adb_write(h->bulk_in, buf, write_len); if (n < 0) { D("ERROR: fd = %d, n = %d: %s", h->bulk_in, n, strerror(errno)); Loading @@ -422,7 +393,7 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) { char* buf = static_cast<char*>(data); while (len > 0) { int read_len = std::min(h->max_rw, len); int read_len = std::min(USB_FFS_BULK_SIZE, len); int n = adb_read(h->bulk_out, buf, read_len); if (n < 0) { D("ERROR: fd = %d, n = %d: %s", h->bulk_out, n, strerror(errno)); Loading adb/daemon/usb.h +0 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,5 @@ struct usb_handle { // read and write threads. struct aio_block read_aiob; struct aio_block write_aiob; int max_rw; }; Loading
adb/daemon/usb.cpp +2 −31 Original line number Diff line number Diff line Loading @@ -58,10 +58,6 @@ using namespace std::chrono_literals; #define cpu_to_le16(x) htole16(x) #define cpu_to_le32(x) htole32(x) #define FUNCTIONFS_ENDPOINT_ALLOC _IOR('g', 231, __u32) static constexpr size_t ENDPOINT_ALLOC_RETRIES = 10; static int dummy_fd = -1; struct func_desc { Loading Loading @@ -256,7 +252,6 @@ bool init_functionfs(struct usb_handle* h) { ssize_t ret; struct desc_v1 v1_descriptor; struct desc_v2 v2_descriptor; size_t retries = 0; v2_descriptor.header.magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2); v2_descriptor.header.length = cpu_to_le32(sizeof(v2_descriptor)); Loading Loading @@ -326,30 +321,6 @@ bool init_functionfs(struct usb_handle* h) { h->read_aiob.fd = h->bulk_out; h->write_aiob.fd = h->bulk_in; h->max_rw = MAX_PAYLOAD; while (h->max_rw >= USB_FFS_BULK_SIZE && retries < ENDPOINT_ALLOC_RETRIES) { int ret_in = ioctl(h->bulk_in, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(h->max_rw)); int errno_in = errno; int ret_out = ioctl(h->bulk_out, FUNCTIONFS_ENDPOINT_ALLOC, static_cast<__u32>(h->max_rw)); int errno_out = errno; if (ret_in || ret_out) { if (errno_in == ENODEV || errno_out == ENODEV) { std::this_thread::sleep_for(100ms); retries += 1; continue; } h->max_rw /= 2; } else { return true; } } D("[ adb: cannot call endpoint alloc: errno=%d ]", errno); // Kernel pre-allocation could have failed for recoverable reasons. // Continue running with a safe max rw size. h->max_rw = USB_FFS_BULK_SIZE; return true; err: Loading Loading @@ -403,7 +374,7 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len) { const char* buf = static_cast<const char*>(data); while (len > 0) { int write_len = std::min(h->max_rw, len); int write_len = std::min(USB_FFS_BULK_SIZE, len); int n = adb_write(h->bulk_in, buf, write_len); if (n < 0) { D("ERROR: fd = %d, n = %d: %s", h->bulk_in, n, strerror(errno)); Loading @@ -422,7 +393,7 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) { char* buf = static_cast<char*>(data); while (len > 0) { int read_len = std::min(h->max_rw, len); int read_len = std::min(USB_FFS_BULK_SIZE, len); int n = adb_read(h->bulk_out, buf, read_len); if (n < 0) { D("ERROR: fd = %d, n = %d: %s", h->bulk_out, n, strerror(errno)); Loading
adb/daemon/usb.h +0 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,5 @@ struct usb_handle { // read and write threads. struct aio_block read_aiob; struct aio_block write_aiob; int max_rw; };