Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/device_discovery_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int nvtop_device_get_syspath(nvtop_device *device, const char **sysPath) {

int nvtop_enumerator_new(nvtop_device_enumerator **enumerator) {
*enumerator = calloc(1, sizeof(**enumerator));
if (!enumerator)
if (!*enumerator)
return -1;
(*enumerator)->refCount = 1;
(*enumerator)->udev = udev_new();
Expand Down Expand Up @@ -342,16 +342,18 @@ nvtop_device *nvtop_device_get_hwmon(nvtop_device *dev) {
int ret = nvtop_enumerator_new(&enumerator);
if (ret < 0)
return NULL;
nvtop_device *hwmon = NULL;
ret = nvtop_device_enumerator_add_match_subsystem(enumerator, "hwmon", true);
if (ret < 0)
return NULL;
goto out;
ret = nvtop_device_enumerator_add_match_parent(enumerator, dev);
if (ret < 0)
return NULL;
nvtop_device *hwmon = nvtop_enumerator_get_device_first(enumerator);
goto out;
hwmon = nvtop_enumerator_get_device_first(enumerator);
if (!hwmon)
return NULL;
goto out;
nvtop_device_ref(hwmon);
out:
nvtop_enumerator_unref(enumerator);
return hwmon;
}
13 changes: 8 additions & 5 deletions src/extract_gpuinfo_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,22 @@ bool gpuinfo_intel_get_device_handles(struct list_head *devices_list, unsigned *
if (nvtop_enumerator_new(&enumerator) < 0)
return false;

bool ret = false;
unsigned num_devices = 0;
if (nvtop_device_enumerator_add_match_subsystem(enumerator, "drm", true) < 0)
return false;
goto out;

if (nvtop_device_enumerator_add_match_property(enumerator, "DEVNAME", "/dev/dri/*") < 0)
return false;
goto out;

unsigned num_devices = 0;
for (nvtop_device *device = nvtop_enumerator_get_device_first(enumerator); device;
device = nvtop_enumerator_get_device_next(enumerator)) {
num_devices++;
}

gpu_infos = calloc(num_devices, sizeof(*gpu_infos));
if (!gpu_infos)
return false;
goto out;

for (nvtop_device *device = nvtop_enumerator_get_device_first(enumerator); device;
device = nvtop_enumerator_get_device_next(enumerator)) {
Expand All @@ -157,8 +158,10 @@ bool gpuinfo_intel_get_device_handles(struct list_head *devices_list, unsigned *
}
}

ret = true;
out:
nvtop_enumerator_unref(enumerator);
return true;
return ret;
}

void gpuinfo_intel_populate_static_info(struct gpu_info *_gpu_info) {
Expand Down
13 changes: 8 additions & 5 deletions src/extract_gpuinfo_v3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,22 @@ bool gpuinfo_v3d_get_device_handles(struct list_head *devices_list, unsigned *co
if (nvtop_enumerator_new(&enumerator) < 0)
return false;

bool ret = false;
unsigned num_devices = 0;
if (nvtop_device_enumerator_add_match_subsystem(enumerator, "drm", true) < 0)
return false;
goto out;

if (nvtop_device_enumerator_add_match_property(enumerator, "DEVNAME", "/dev/dri/*") < 0)
return false;
goto out;

unsigned num_devices = 0;
for (nvtop_device *device = nvtop_enumerator_get_device_first(enumerator); device;
device = nvtop_enumerator_get_device_next(enumerator)) {
num_devices++;
}

gpu_infos = calloc(num_devices, sizeof(*gpu_infos));
if (!gpu_infos)
return false;
goto out;

for (nvtop_device *device = nvtop_enumerator_get_device_first(enumerator); device;
device = nvtop_enumerator_get_device_next(enumerator)) {
Expand All @@ -247,8 +248,10 @@ bool gpuinfo_v3d_get_device_handles(struct list_head *devices_list, unsigned *co
}
}

ret = true;
out:
nvtop_enumerator_unref(enumerator);
return true;
return ret;
}

void gpuinfo_v3d_populate_static_info(struct gpu_info *_gpu_info) {
Expand Down