Commit 3b3364b0 authored by garcialasheras's avatar garcialasheras

Fixing the automatic scan for available SPEC boards

parent 5154cd5e
...@@ -82,43 +82,38 @@ static int spec_check_id(int bus, int dev) ...@@ -82,43 +82,38 @@ static int spec_check_id(int bus, int dev)
static int spec_scan(int *bus, int *devfn) static int spec_scan(int *bus, int *devfn)
{ {
struct dirent **namelist; struct dirent **namelist;
int n, found = 0; int n, i, found = 0;
int my_bus, my_devfn; int my_bus, my_devfn;
if (*bus < 0 || *devfn < 0) // Automatic search for the first availabe card
n = scandir("/sys/bus/pci/devices/", &namelist, 0, 0);
if (n < 0)
{ {
// Automatic search for the first availabe card perror("scandir");
n = scandir("/sys/bus/pci/devices/", &namelist, 0, 0); exit(-1);
if (n < 0) } else {
for(i=0; i<n; i++)
{ {
perror("scandir"); if(!found && sscanf(namelist[i]->d_name,
exit(-1); "0000:%02x:%02x.0",
} else { &my_bus, &my_devfn) == 2)
while (n--)
{ {
if(!found && sscanf(namelist[n]->d_name, if (*bus >= 0) my_bus = *bus;
"0000:%02x:%02x.0", if (*devfn >= 0) my_devfn = *devfn;
&my_bus, &my_devfn) == 2) if (spec_check_id(my_bus, my_devfn))
{ {
if (spec_check_id(my_bus, my_devfn)) *bus = my_bus;
{ *devfn = my_devfn;
*bus = my_bus; found = 1;
*devfn = my_devfn;
found = 1;
}
} }
free(namelist[n]);
} }
free(namelist); free(namelist[i]);
} }
free(namelist);
} else {
// Check if the requested card is available
if (spec_check_id(*bus, *devfn))
found = 1;
} }
if(!found) if(!found)
{ {
fprintf(stderr,"Can't detect any SPEC card :(\n"); fprintf(stderr,"Can't detect any SPEC card :(\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment