From c723bbd6be642ab939fa183fb065fc4928069b3c Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Fri, 29 Jan 2021 20:00:49 +0800 Subject: [PATCH] Panda: add check for connected in usb_read (#19957) --- selfdrive/boardd/panda.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/selfdrive/boardd/panda.cc b/selfdrive/boardd/panda.cc index 0bc72cff63..8f9525fb61 100644 --- a/selfdrive/boardd/panda.cc +++ b/selfdrive/boardd/panda.cc @@ -118,6 +118,10 @@ int Panda::usb_read(uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned int err; const uint8_t bmRequestType = LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE; + if (!connected){ + return LIBUSB_ERROR_NO_DEVICE; + } + std::lock_guard lk(usb_lock); do { err = libusb_control_transfer(dev_handle, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout);