fastbootd: Add more logging for when the USB transport fails.
Bug: 161542676
Test: fastboot flashall
Change-Id: Ief4e7452b72504c51c807dd38a07765ad65c96a4
diff --git a/fastboot/device/fastboot_device.cpp b/fastboot/device/fastboot_device.cpp
index 52ea9f0..35f3de0 100644
--- a/fastboot/device/fastboot_device.cpp
+++ b/fastboot/device/fastboot_device.cpp
@@ -139,7 +139,13 @@
bool FastbootDevice::HandleData(bool read, std::vector<char>* 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<size_t>(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<size_t>(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 c653167..2caced4 100644
--- a/fastboot/device/usb_client.cpp
+++ b/fastboot/device/usb_client.cpp
@@ -248,7 +248,12 @@
}
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<char*>(data);
@@ -258,6 +263,7 @@
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;