Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7dd382de authored by Josh Gao's avatar Josh Gao
Browse files

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
Change-Id: I2517dcb9d30d9a08cebbb5f715ae3fd30c510109
parent 3160a250
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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 << "'";
}