From 33ae5ab8b9c2f171913517a4dd1c2e770b791729 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 31 Aug 2013 21:31:32 +1000 Subject: [PATCH] Use an internal buffer in _usb_transfer_read in case the read is larger than the buffer passed to it. --- usbutils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usbutils.c b/usbutils.c index 1a0fa75d..12092c5b 100644 --- a/usbutils.c +++ b/usbutils.c @@ -2812,6 +2812,7 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe #if DO_USB_STATS struct timeval tv_start, tv_finish; #endif + unsigned char tbuf[64]; int err, pstate; DEVLOCK(cgpu, pstate); @@ -2846,14 +2847,16 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe cgpu->usbinfo.total_read_delay += sleep_estimate; } } + memset(tbuf, 0, 64); STATS_TIMEVAL(&tv_start); cg_rlock(&cgusb_fd_lock); err = libusb_control_transfer(usbdev->handle, request_type, bRequest, wValue, wIndex, - (unsigned char *)buf, (uint16_t)bufsiz, timeout); + tbuf, (uint16_t)bufsiz, timeout); cg_runlock(&cgusb_fd_lock); STATS_TIMEVAL(&tv_finish); USB_STATS(cgpu, &tv_start, &tv_finish, err, MODE_CTRL_READ, cmd, SEQ0, timeout); + memcpy(buf, tbuf, bufsiz); USBDEBUG("USB debug: @_usb_transfer_read(%s (nodev=%s)) amt/err=%d%s%s%s", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), err > 0 ? " = " : BLANK, err > 0 ? bin2hex((unsigned char *)buf, (size_t)err) : BLANK);