From f74c1a955617b9b571f9439b43cc618d5aba354b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 12 Oct 2020 15:54:49 -0700 Subject: [PATCH] fastbootd: Add more logging for when the USB transport fails. Bug: 161542676 Test: fastboot flashall Change-Id: Ief4e7452b72504c51c807dd38a07765ad65c96a4 --- fastboot/device/fastboot_device.cpp | 8 +++++++- fastboot/device/usb_client.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fastboot/device/fastboot_device.cpp b/fastboot/device/fastboot_device.cpp index 52ea9f006..35f3de020 100644 --- a/fastboot/device/fastboot_device.cpp +++ b/fastboot/device/fastboot_device.cpp @@ -139,7 +139,13 @@ bool FastbootDevice::WriteStatus(FastbootResult result, const std::string& messa bool FastbootDevice::HandleData(bool read, std::vector* data) { auto read_write_data_size = read ? this->get_transport()->Read(data->data(), data->size()) : this->get_transport()->Write(data->data(), data->size()); - if (read_write_data_size == -1 || static_cast(read_write_data_size) != data->size()) { + if (read_write_data_size == -1) { + LOG(ERROR) << (read ? "read from" : "write to") << " transport failed"; + return false; + } + if (static_cast(read_write_data_size) != data->size()) { + LOG(ERROR) << (read ? "read" : "write") << " expected " << data->size() << " bytes, got " + << read_write_data_size; return false; } return true; diff --git a/fastboot/device/usb_client.cpp b/fastboot/device/usb_client.cpp index c65316707..2caced476 100644 --- a/fastboot/device/usb_client.cpp +++ b/fastboot/device/usb_client.cpp @@ -248,7 +248,12 @@ ClientUsbTransport::ClientUsbTransport() } ssize_t ClientUsbTransport::Read(void* data, size_t len) { - if (handle_ == nullptr || len > SSIZE_MAX) { + if (handle_ == nullptr) { + LOG(ERROR) << "ClientUsbTransport: no handle"; + return -1; + } + if (len > SSIZE_MAX) { + LOG(ERROR) << "ClientUsbTransport: maximum length exceeds bounds"; return -1; } char* char_data = static_cast(data); @@ -258,6 +263,7 @@ ssize_t ClientUsbTransport::Read(void* data, size_t len) { auto bytes_read_now = handle_->read(handle_.get(), char_data, bytes_to_read, true /* allow_partial */); if (bytes_read_now < 0) { + PLOG(ERROR) << "ClientUsbTransport: read failed"; return bytes_read_total == 0 ? -1 : bytes_read_total; } bytes_read_total += bytes_read_now;