From 0b19540dee9d0eee56f87705eea771b13800290f Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 16 Dec 2015 11:00:08 -0800 Subject: [PATCH] adb: split up reads longer than 16k. Reads from functionfs allocate contiguous buffers in the kernel, causing long ones to sometimes fail because of memory fragmentation. Bug: http://b/26206622 Change-Id: Id40753d6f29b37b5ca97c3e2fa3921f52b4242de --- adb/usb_linux_client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adb/usb_linux_client.cpp b/adb/usb_linux_client.cpp index ceed8facf..151c0aa11 100644 --- a/adb/usb_linux_client.cpp +++ b/adb/usb_linux_client.cpp @@ -481,7 +481,8 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) { char* buf = static_cast(data); while (len > 0) { - int n = adb_read(h->bulk_out, buf, len); + int read_len = (len > 16384) ? 16384 : 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)); return -1;