Convert uses of usbutils memcpy to cg_memcpy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/usbutils.c b/usbutils.c
index 3882507..6c6d902 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1731,7 +1731,7 @@ static bool __release_cgpu(struct cgpu_info *cgpu)
lookcgpu->usbinfo.nodev = true;
lookcgpu->usbinfo.nodev_count++;
- memcpy(&(lookcgpu->usbinfo.last_nodev),
+ cg_memcpy(&(lookcgpu->usbinfo.last_nodev),
&(cgpu->usbinfo.last_nodev), sizeof(struct timeval));
lookcgpu->usbdev = NULL;
}
@@ -1804,7 +1804,7 @@ struct cgpu_info *usb_copy_cgpu(struct cgpu_info *orig)
copy->usbdev = orig->usbdev;
- memcpy(&(copy->usbinfo), &(orig->usbinfo), sizeof(copy->usbinfo));
+ cg_memcpy(&(copy->usbinfo), &(orig->usbinfo), sizeof(copy->usbinfo));
copy->usbinfo.nodev = (copy->usbdev == NULL);
@@ -2202,7 +2202,7 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
found_use = malloc(sizeof(*found_use));
if (unlikely(!found_use))
quit(1, "USB failed to malloc found_use");
- memcpy(found_use, &(find_dev[i]), sizeof(*found_use));
+ cg_memcpy(found_use, &(find_dev[i]), sizeof(*found_use));
ret = _usb_init(cgpu, dev, found_use);
@@ -2278,7 +2278,7 @@ static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *dr
found = malloc(sizeof(*found));
if (unlikely(!found))
quit(1, "USB failed to malloc found");
- memcpy(found, &(find_dev[i]), sizeof(*found));
+ cg_memcpy(found, &(find_dev[i]), sizeof(*found));
return found;
}
}
@@ -2595,7 +2595,7 @@ static void stats(struct cgpu_info *cgpu, struct timeval *tv_start, struct timev
if (details->item[item].count == 0) {
details->item[item].min_delay = diff;
- memcpy(&(details->item[item].first), tv_start, sizeof(*tv_start));
+ cg_memcpy(&(details->item[item].first), tv_start, sizeof(*tv_start));
} else if (diff < details->item[item].min_delay)
details->item[item].min_delay = diff;
@@ -2603,7 +2603,7 @@ static void stats(struct cgpu_info *cgpu, struct timeval *tv_start, struct timev
details->item[item].max_delay = diff;
details->item[item].total_delay += diff;
- memcpy(&(details->item[item].last), tv_start, sizeof(*tv_start));
+ cg_memcpy(&(details->item[item].last), tv_start, sizeof(*tv_start));
details->item[item].count++;
}
@@ -2807,7 +2807,7 @@ err_retry:
init_usb_transfer(&ut);
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
- memcpy(buf, data, length);
+ cg_memcpy(buf, data, length);
#ifndef HAVE_LIBUSB
/* Older versions may not have this feature so only enable it
* when we know we're compiling with included static libusb. We
@@ -2875,7 +2875,7 @@ err_retry:
if (NODEV(err))
*transferred = 0;
else if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
- memcpy(data, buf, *transferred);
+ cg_memcpy(data, buf, *transferred);
return err;
}
@@ -2948,7 +2948,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
tot = usbdev->bufamt;
bufleft = bufsiz - tot;
if (tot)
- memcpy(usbbuf, usbdev->buffer, tot);
+ cg_memcpy(usbbuf, usbdev->buffer, tot);
ptr = usbbuf + tot;
usbdev->bufamt = 0;
@@ -3030,7 +3030,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
// N.B. usbdev->buffer was emptied before the while() loop
if (tot > (int)bufsiz) {
usbdev->bufamt = tot - bufsiz;
- memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
+ cg_memcpy(usbdev->buffer, usbbuf + bufsiz, usbdev->bufamt);
tot -= usbdev->bufamt;
usbbuf[tot] = '\0';
applog(LOG_DEBUG, "USB: %s%i read1 buffering %d extra bytes",
@@ -3038,7 +3038,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
}
*processed = tot;
- memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
+ cg_memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz);
out_noerrmsg:
if (NODEV(err)) {
@@ -3167,7 +3167,8 @@ static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *de
libusb_fill_control_setup(buf, bmRequestType, bRequest, wValue,
wIndex, wLength);
if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
- memcpy(buf + LIBUSB_CONTROL_SETUP_SIZE, buffer, wLength);
+ if (wLength)
+ cg_memcpy(buf + LIBUSB_CONTROL_SETUP_SIZE, buffer, wLength);
if (cgpu->usbdev->descriptor->bcdUSB < 0x0200)
tt = true;
}
@@ -3178,7 +3179,7 @@ static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *de
err = callback_wait(&ut, &transferred, timeout);
if (err == LIBUSB_SUCCESS && transferred) {
if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
- memcpy(buffer, libusb_control_transfer_get_data(ut.transfer),
+ cg_memcpy(buffer, libusb_control_transfer_get_data(ut.transfer),
transferred);
err = transferred;
goto out;
@@ -3290,7 +3291,7 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
wValue, wIndex, tbuf, (uint16_t)bufsiz, timeout);
STATS_TIMEVAL(&tv_finish);
USB_STATS(cgpu, &tv_start, &tv_finish, err, MODE_CTRL_READ, cmd, SEQ0, timeout);
- memcpy(buf, tbuf, bufsiz);
+ cg_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);