summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-06-01 15:34:21 -0700
committerJosh Gao <jmgao@google.com>2017-06-07 11:29:14 -0700
commitf74dd42e4e20bc09748aa5157186b05bdf31f74a (patch)
tree7ad0b8682a3fd79a17b3db5a49ff9e65b7135eeb
parent435baf5d00162b6f14ada5f243ae49c62714d03f (diff)
downloadsystem_core-f74dd42e4e20bc09748aa5157186b05bdf31f74a.tar.gz
system_core-f74dd42e4e20bc09748aa5157186b05bdf31f74a.tar.bz2
system_core-f74dd42e4e20bc09748aa5157186b05bdf31f74a.zip
adb: improve race between device_connected and device_disconnected.
If a device is unplugged while it's being processed, we can be inside register_usb_transport still when we call unregister_usb_transport, leading to bad things happening. Move the call of register_usb_transport into the scope guarded by usb_handles_mutex. Bug: http://b/62200735 Test: manual Merged-In: I2517dcb9d30d9a08cebbb5f715ae3fd30c510109 Change-Id: I2517dcb9d30d9a08cebbb5f715ae3fd30c510109 (cherry picked from commit 7dd382ded948aa5adae3618f99d00c14c3703d05)
-rw-r--r--adb/client/usb_libusb.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/adb/client/usb_libusb.cpp b/adb/client/usb_libusb.cpp
index b2fdc07f0..dc1a6b476 100644
--- a/adb/client/usb_libusb.cpp
+++ b/adb/client/usb_libusb.cpp
@@ -377,9 +377,10 @@ static void process_device(libusb_device* device) {
{
std::unique_lock<std::mutex> lock(usb_handles_mutex);
usb_handles[device_address] = std::move(result);
- }
- register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(), writable);
+ register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(),
+ writable);
+ }
LOG(INFO) << "registered new usb device '" << device_serial << "'";
}