Merge "adb: disable USB packet overflow checking on OS X."

This commit is contained in:
Treehugger Robot 2017-12-08 20:31:51 +00:00 committed by Gerrit Code Review
commit a4a9a81d38
2 changed files with 15 additions and 0 deletions

View File

@ -305,6 +305,7 @@ AndroidInterfaceAdded(io_iterator_t iterator)
handle->devpath = devpath;
usb_handle* handle_p = handle.get();
VLOG(USB) << "Add usb device " << serial;
LOG(INFO) << "reported max packet size for " << serial << " is " << handle->max_packet_size;
AddDevice(std::move(handle));
register_usb_transport(reinterpret_cast<::usb_handle*>(handle_p), serial, devpath.c_str(),
1);

View File

@ -27,11 +27,18 @@
#if ADB_HOST
#if defined(__APPLE__)
#define CHECK_PACKET_OVERFLOW 0
#else
#define CHECK_PACKET_OVERFLOW 1
#endif
// Call usb_read using a buffer having a multiple of usb_get_max_packet_size() bytes
// to avoid overflow. See http://libusb.sourceforge.net/api-1.0/packetoverflow.html.
static int UsbReadMessage(usb_handle* h, amessage* msg) {
D("UsbReadMessage");
#if CHECK_PACKET_OVERFLOW
size_t usb_packet_size = usb_get_max_packet_size(h);
CHECK_GE(usb_packet_size, sizeof(*msg));
CHECK_LT(usb_packet_size, 4096ULL);
@ -44,6 +51,9 @@ static int UsbReadMessage(usb_handle* h, amessage* msg) {
}
memcpy(msg, buffer, sizeof(*msg));
return n;
#else
return usb_read(h, msg, sizeof(*msg));
#endif
}
// Call usb_read using a buffer having a multiple of usb_get_max_packet_size() bytes
@ -51,6 +61,7 @@ static int UsbReadMessage(usb_handle* h, amessage* msg) {
static int UsbReadPayload(usb_handle* h, apacket* p) {
D("UsbReadPayload(%d)", p->msg.data_length);
#if CHECK_PACKET_OVERFLOW
size_t usb_packet_size = usb_get_max_packet_size(h);
CHECK_EQ(0ULL, sizeof(p->data) % usb_packet_size);
@ -64,6 +75,9 @@ static int UsbReadPayload(usb_handle* h, apacket* p) {
}
CHECK_LE(len, sizeof(p->data));
return usb_read(h, &p->data, len);
#else
return usb_read(h, &p->data, p->msg.data_length);
#endif
}
static int remote_read(apacket* p, atransport* t) {