From 8efadf70e10fcc12e227e98e838e7544fc26256c Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Mon, 15 Apr 2019 10:27:38 -0700 Subject: [PATCH] Handle failed usb/reads and writes correctly Currently if the device is unplugged from host, there is a lot of log spamming since fastbootd does not not recognize that the device has been disconnected and keeps trying to read/write to the device. 2856 printk messages dropped ** [ 169.941904] c7 579 fastbootd: aio: got error event on read total bufs 1: No such devie ** 2960 printk messages dropped ** [ 169.953328] c7 579 fastbootd: Fastboot command: ** 2074 printk messages dropped ** [ 169.961355] c7 579 fastbootd: aio: got error event on read total bufs 1: No such devie Bug: 121333158 Test: unplug device and check for log spam multiple times Change-Id: I1d4c6f48f34e313c5ebce23d62a4fe6a6373f94f --- fastboot/device/usb_client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastboot/device/usb_client.cpp b/fastboot/device/usb_client.cpp index fb51a900b..511bd5c94 100644 --- a/fastboot/device/usb_client.cpp +++ b/fastboot/device/usb_client.cpp @@ -257,7 +257,7 @@ ssize_t ClientUsbTransport::Read(void* data, size_t len) { auto bytes_to_read = std::min(len - bytes_read_total, kFbFfsNumBufs * kFbFfsBufSize); auto bytes_read_now = handle_->read(handle_.get(), char_data, bytes_to_read); if (bytes_read_now < 0) { - return bytes_read_total; + return bytes_read_total == 0 ? -1 : bytes_read_total; } bytes_read_total += bytes_read_now; char_data += bytes_read_now; @@ -278,7 +278,7 @@ ssize_t ClientUsbTransport::Write(const void* data, size_t len) { auto bytes_to_write = std::min(len - bytes_written_total, kFbFfsNumBufs * kFbFfsBufSize); auto bytes_written_now = handle_->write(handle_.get(), data, bytes_to_write); if (bytes_written_now < 0) { - return bytes_written_total; + return bytes_written_total == 0 ? -1 : bytes_written_total; } bytes_written_total += bytes_written_now; char_data += bytes_written_now;