unsigned os_index;
char path[64];
char value[16];
+ size_t read;
FILE *file;
if (sscanf(dirent->d_name, "%04x:%02x:%02x.%01x", &domain, &bus, &dev, &func) != 4)
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/vendor", dirent->d_name);
file = hwloc_fopen(path, "r", root_fd);
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- attr->vendor_id = strtoul(value, NULL, 16);
+ if (read)
+ attr->vendor_id = strtoul(value, NULL, 16);
}
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/device", dirent->d_name);
file = hwloc_fopen(path, "r", root_fd);
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- attr->device_id = strtoul(value, NULL, 16);
+ if (read)
+ attr->device_id = strtoul(value, NULL, 16);
}
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/class", dirent->d_name);
file = hwloc_fopen(path, "r", root_fd);
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- attr->class_id = strtoul(value, NULL, 16) >> 8;
+ if (read)
+ attr->class_id = strtoul(value, NULL, 16) >> 8;
}
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/subsystem_vendor", dirent->d_name);
file = hwloc_fopen(path, "r", root_fd);
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- attr->subvendor_id = strtoul(value, NULL, 16);
+ if (read)
+ attr->subvendor_id = strtoul(value, NULL, 16);
}
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/subsystem_device", dirent->d_name);
file = hwloc_fopen(path, "r", root_fd);
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- attr->subdevice_id = strtoul(value, NULL, 16);
+ if (read)
+ attr->subdevice_id = strtoul(value, NULL, 16);
}
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/config", dirent->d_name);
/* initialize the config space in case we fail to read it (missing permissions, etc). */
memset(config_space_cache, 0xff, CONFIG_SPACE_CACHESIZE);
- (void) fread(config_space_cache, 1, CONFIG_SPACE_CACHESIZE, file);
+ read = fread(config_space_cache, 1, CONFIG_SPACE_CACHESIZE, file);
+ (void) read; /* we initialized config_space_cache in case we don't read enough, ignore the read length */
fclose(file);
/* is this a bridge? */
char path[64];
char value[16];
FILE *file;
+ size_t read;
+
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/vendor",
domain, pcidev->bus, pcidev->dev, pcidev->func);
file = fopen(path, "r");
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- obj->attr->pcidev.vendor_id = strtoul(value, NULL, 16);
+ if (read)
+ obj->attr->pcidev.vendor_id = strtoul(value, NULL, 16);
}
+
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/device",
domain, pcidev->bus, pcidev->dev, pcidev->func);
file = fopen(path, "r");
if (file) {
- fread(value, sizeof(value), 1, file);
+ read = fread(value, sizeof(value), 1, file);
fclose(file);
- obj->attr->pcidev.device_id = strtoul(value, NULL, 16);
+ if (read)
+ obj->attr->pcidev.device_id = strtoul(value, NULL, 16);
}
#endif
}