diff --git a/driver-avalon2.c b/driver-avalon2.c index 2ce216d6c6..e34dc19e83 100644 --- a/driver-avalon2.c +++ b/driver-avalon2.c @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 Con Kolivas + * Copyright 2013-2015 Con Kolivas * Copyright 2012-2014 Xiangfu * Copyright 2012 Luke Dashjr * Copyright 2012 Andrew Smith @@ -693,9 +693,7 @@ static struct cgpu_info *avalon2_detect_one(struct libusb_device *dev, struct us applog(LOG_INFO, "%s %d: Found at %s", avalon2->drv->name, avalon2->device_id, avalon2->device_path); - avalon2->device_data = calloc(sizeof(struct avalon2_info), 1); - if (unlikely(!(avalon2->device_data))) - quit(1, "Failed to calloc avalon2_info"); + avalon2->device_data = cgcalloc(sizeof(struct avalon2_info), 1); info = avalon2->device_data; @@ -795,22 +793,16 @@ static void copy_pool_stratum(struct avalon2_info *info, struct pool *pool) free(pool_stratum->nonce1); free(pool_stratum->coinbase); - align_len(&coinbase_len); - pool_stratum->coinbase = calloc(coinbase_len, 1); - if (unlikely(!pool_stratum->coinbase)) - quit(1, "Failed to calloc pool_stratum coinbase in avalon2"); + pool_stratum->coinbase = cgcalloc(coinbase_len, 1); memcpy(pool_stratum->coinbase, pool->coinbase, coinbase_len); - for (i = 0; i < pool_stratum->merkles; i++) free(pool_stratum->swork.merkle_bin[i]); if (merkles) { - pool_stratum->swork.merkle_bin = realloc(pool_stratum->swork.merkle_bin, - sizeof(char *) * merkles + 1); + pool_stratum->swork.merkle_bin = cgrealloc(pool_stratum->swork.merkle_bin, + sizeof(char *) * merkles + 1); for (i = 0; i < merkles; i++) { - pool_stratum->swork.merkle_bin[i] = malloc(32); - if (unlikely(!pool_stratum->swork.merkle_bin[i])) - quit(1, "Failed to malloc pool_stratum swork merkle_bin"); + pool_stratum->swork.merkle_bin[i] = cgmalloc(32); memcpy(pool_stratum->swork.merkle_bin[i], pool->swork.merkle_bin[i], 32); } } diff --git a/driver-avalon4.c b/driver-avalon4.c index fec71de4dd..3790de01c3 100644 --- a/driver-avalon4.c +++ b/driver-avalon4.c @@ -1143,7 +1143,6 @@ static void copy_pool_stratum(struct pool *pool_stratum, struct pool *pool) free(pool_stratum->nonce1); free(pool_stratum->coinbase); - align_len(&coinbase_len); pool_stratum->coinbase = cgcalloc(coinbase_len, 1); memcpy(pool_stratum->coinbase, pool->coinbase, coinbase_len); diff --git a/driver-hashratio.c b/driver-hashratio.c index 511e834680..4f722e880b 100644 --- a/driver-hashratio.c +++ b/driver-hashratio.c @@ -609,9 +609,7 @@ static struct cgpu_info *hashratio_detect_one(struct libusb_device *dev, struct applog(LOG_INFO, "%s%d: Found at %s", hashratio->drv->name, hashratio->device_id, hashratio->device_path); - hashratio->device_data = calloc(sizeof(struct hashratio_info), 1); - if (unlikely(!(hashratio->device_data))) - quit(1, "Failed to malloc hashratio_info"); + hashratio->device_data = cgcalloc(sizeof(struct hashratio_info), 1); info = hashratio->device_data; @@ -657,22 +655,16 @@ static void copy_pool_stratum(struct hashratio_info *info, struct pool *pool) free(pool_stratum->nonce1); free(pool_stratum->coinbase); - align_len(&coinbase_len); - pool_stratum->coinbase = calloc(coinbase_len, 1); - if (unlikely(!pool_stratum->coinbase)) - quit(1, "Failed to calloc pool_stratum coinbase in hashratio"); + pool_stratum->coinbase = cgcalloc(coinbase_len, 1); memcpy(pool_stratum->coinbase, pool->coinbase, coinbase_len); - for (i = 0; i < pool_stratum->merkles; i++) free(pool_stratum->swork.merkle_bin[i]); if (merkles) { - pool_stratum->swork.merkle_bin = realloc(pool_stratum->swork.merkle_bin, - sizeof(char *) * merkles + 1); + pool_stratum->swork.merkle_bin = cgrealloc(pool_stratum->swork.merkle_bin, + sizeof(char *) * merkles + 1); for (i = 0; i < merkles; i++) { - pool_stratum->swork.merkle_bin[i] = malloc(32); - if (unlikely(!pool_stratum->swork.merkle_bin[i])) - quit(1, "Failed to malloc pool_stratum swork merkle_bin"); + pool_stratum->swork.merkle_bin[i] = cgmalloc(32); memcpy(pool_stratum->swork.merkle_bin[i], pool->swork.merkle_bin[i], 32); } } diff --git a/util.c b/util.c index 9fe2a1bcf6..483b0e4866 100644 --- a/util.c +++ b/util.c @@ -253,6 +253,13 @@ int Inet_Pton(int af, const char *src, void *dst) } #endif +/* Align a size_t to 4 byte boundaries for fussy arches */ +static inline void align_len(size_t *len) +{ + if (*len % 4) + *len += 4 - (*len % 4); +} + void *_cgmalloc(size_t size, const char *file, const char *func, const int line) { void *ret; diff --git a/util.h b/util.h index 5ea96ecf6f..8a911a8d15 100644 --- a/util.h +++ b/util.h @@ -175,11 +175,4 @@ void _cg_memcpy(void *dest, const void *src, unsigned int n, const char *file, c #define cgsem_mswait(_sem, _timeout) _cgsem_mswait(_sem, _timeout, __FILE__, __func__, __LINE__) #define cg_memcpy(dest, src, n) _cg_memcpy(dest, src, n, __FILE__, __func__, __LINE__) -/* Align a size_t to 4 byte boundaries for fussy arches */ -static inline void align_len(size_t *len) -{ - if (*len % 4) - *len += 4 - (*len % 4); -} - #endif /* __UTIL_H__ */