From f3093803d16e6a989aeffb62041d42c0cf5f8a20 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 29 May 2013 16:29:49 +1000 Subject: [PATCH] Check for valid usbdev in _usb_read in case the device has been unplugged. --- usbutils.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/usbutils.c b/usbutils.c index 39741ae6..3a945a7c 100644 --- a/usbutils.c +++ b/usbutils.c @@ -2011,7 +2011,7 @@ static void rejected_inc(struct cgpu_info *cgpu, uint32_t mode) int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, __maybe_unused enum usb_cmds cmd, bool readonce) { struct cg_usb_device *usbdev = cgpu->usbdev; - bool ftdi = (usbdev->usb_type == USB_TYPE_FTDI); + bool ftdi; #if DO_USB_STATS struct timeval tv_start; #endif @@ -2027,6 +2027,11 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro unsigned char usbbuf[USB_MAX_READ+4], *ptr; size_t usbbufread; + if (unlikely(!usbdev)) + return LIBUSB_ERROR_NO_DEVICE; + + ftdi = (usbdev->usb_type == USB_TYPE_FTDI); + USBDEBUG("USB debug: _usb_read(%s (nodev=%s),ep=%d,buf=%p,bufsiz=%zu,proc=%p,timeout=%u,end=%s,cmd=%s,ftdi=%s,readonce=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), ep, buf, bufsiz, processed, timeout, end ? (char *)str_text((char *)end) : "NULL", usb_cmdname(cmd), bool_str(ftdi), bool_str(readonce)); if (bufsiz > USB_MAX_READ)