Make the devices array a dynamically allocated array of pointers to allow unlimited devices.
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/cgminer.c b/cgminer.c
index a6232a4..3dc506b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -116,7 +116,7 @@ struct list_head scan_devices;
static signed int devices_enabled;
static bool opt_removedisabled;
int total_devices;
-struct cgpu_info *devices[MAX_DEVICES];
+struct cgpu_info **devices;
bool have_opencl;
int opt_n_threads = -1;
int mining_threads;
@@ -4936,6 +4936,7 @@ bool add_cgpu(struct cgpu_info*cgpu)
cgpu->device_id = d->lastid = 0;
HASH_ADD_STR(devids, name, d);
}
+ devices = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + 2));
devices[total_devices++] = cgpu;
return true;
}
@@ -5025,8 +5026,6 @@ int main(int argc, char *argv[])
gpus[i].dynamic = true;
#endif
- memset(devices, 0, sizeof(devices));
-
/* parse command line */
opt_register_table(opt_config_table,
"Options for both config file and command line");
diff --git a/driver-cpu.c b/driver-cpu.c
index d0a2516..1f8ac89 100644
--- a/driver-cpu.c
+++ b/driver-cpu.c
@@ -731,8 +731,6 @@ static void cpu_detect()
if (num_processors < 1)
return;
- if (total_devices + opt_n_threads > MAX_DEVICES)
- opt_n_threads = MAX_DEVICES - total_devices;
cpus = calloc(opt_n_threads, sizeof(struct cgpu_info));
if (unlikely(!cpus))
quit(1, "Failed to calloc cpus");
diff --git a/driver-icarus.c b/driver-icarus.c
index a463c28..e27a162 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -179,7 +179,7 @@ struct ICARUS_INFO {
};
// One for each possible device
-static struct ICARUS_INFO *icarus_info[MAX_DEVICES];
+static struct ICARUS_INFO **icarus_info;
struct device_api icarus_api;
@@ -421,6 +421,7 @@ static bool icarus_detect_one(const char *devpath)
icarus->device_path = strdup(devpath);
icarus->threads = 1;
add_cgpu(icarus);
+ icarus_info = realloc(icarus_info, sizeof(struct ICARUS_INFO *) * (total_devices + 2));
applog(LOG_INFO, "Found Icarus at %s, mark as %d",
devpath, icarus->device_id);
diff --git a/driver-opencl.c b/driver-opencl.c
index 2d6f975..17be40a 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -1126,9 +1126,6 @@ static void opencl_detect()
nDevs = 0;
}
- if (MAX_DEVICES - total_devices < nDevs)
- nDevs = MAX_DEVICES - total_devices;
-
if (!nDevs)
return;
diff --git a/driver-ztex.c b/driver-ztex.c
index c881cd7..e38be74 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -66,8 +66,6 @@ static void ztex_detect(void)
applog(LOG_WARNING, "Found %d ztex board(s)", cnt);
for (i = 0; i < cnt; i++) {
- if (total_devices == MAX_DEVICES)
- break;
ztex = calloc(1, sizeof(struct cgpu_info));
ztex->api = &ztex_api;
ztex->device_ztex = ztex_devices[i]->dev;
diff --git a/fpgautils.c b/fpgautils.c
index 70387c6..14c1c79 100644
--- a/fpgautils.c
+++ b/fpgautils.c
@@ -40,9 +40,6 @@
char
serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
{
- if (total_devices == MAX_DEVICES)
- return 0;
-
struct udev *udev = udev_new();
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
struct udev_list_entry *list_entry;
@@ -64,9 +61,6 @@ serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
++found;
udev_device_unref(device);
-
- if (total_devices == MAX_DEVICES)
- break;
}
udev_enumerate_unref(enumerate);
udev_unref(udev);
@@ -85,9 +79,6 @@ char
serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
{
#ifndef WIN32
- if (total_devices == MAX_DEVICES)
- return 0;
-
DIR *D;
struct dirent *de;
const char udevdir[] = "/dev/serial/by-id";
@@ -104,11 +95,8 @@ serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
if (!strstr(de->d_name, prodname))
continue;
strcpy(devfile, de->d_name);
- if (detectone(devpath)) {
+ if (detectone(devpath))
++found;
- if (total_devices == MAX_DEVICES)
- break;
- }
}
closedir(D);
@@ -121,9 +109,6 @@ serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
char
_serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
{
- if (total_devices == MAX_DEVICES)
- return 0;
-
struct string_elist *iter, *tmp;
const char*s, *p;
bool inhibitauto = false;
@@ -148,12 +133,10 @@ _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t aut
string_elist_del(iter);
inhibitauto = true;
++found;
- if (total_devices == MAX_DEVICES)
- break;
}
}
- if ((forceauto || !inhibitauto) && autoscan && total_devices < MAX_DEVICES)
+ if ((forceauto || !inhibitauto) && autoscan)
found += autoscan();
return found;
diff --git a/miner.h b/miner.h
index 78d3b80..66d7571 100644
--- a/miner.h
+++ b/miner.h
@@ -585,7 +585,6 @@ extern int add_pool_details(bool live, char *url, char *user, char *pass);
#define ADD_POOL_OK 0
#define MAX_GPUDEVICES 16
-#define MAX_DEVICES 64
#define MAX_POOLS (32)
#define MIN_INTENSITY -10
@@ -607,7 +606,7 @@ extern double total_secs;
extern int mining_threads;
extern struct cgpu_info *cpus;
extern int total_devices;
-extern struct cgpu_info *devices[];
+extern struct cgpu_info **devices;
extern int total_pools;
extern struct pool *pools[MAX_POOLS];
extern const char *algo_names[];