From afdddabc0c40453f490eb0aacade35d864b05643 Mon Sep 17 00:00:00 2001 From: moosecrap Date: Sat, 1 Feb 2025 00:29:48 -0800 Subject: [PATCH] Only read Nvidia i2c devices --- evga-card.c | 18 +++++++++++++++--- evga-card.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/evga-card.c b/evga-card.c index 1cecfe4..88102b3 100644 --- a/evga-card.c +++ b/evga-card.c @@ -13,6 +13,7 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus) char i2c_devices_path[NAME_MAX]; char device_path[NAME_MAX]; char dev_file[NAME_MAX]; + char *pci_addr; FILE *test_fd; DIR *dir; @@ -39,6 +40,11 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus) strcpy(device_path, i2c_devices_path); strcat(device_path, ent->d_name); + /* Only check Nvidia devices */ + pci_addr = read_nvidia_pci_address(device_path); + if (pci_addr == NULL) + continue; + /* Read the PCI info for the underlying device */ pci_vendor = read_pci_id(device_path, "/device/vendor"); pci_device = read_pci_id(device_path, "/device/device"); @@ -59,7 +65,7 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus) if (check_for_icx3(dev_file)) { /* Write our card info into the provided struct array */ infos[num_gpus].card_name = evga_pci_ids[i].card_name; - infos[num_gpus].pci_id = read_nvidia_pci_address(device_path); + infos[num_gpus].pci_id = pci_addr; infos[num_gpus].i2c_dev_path = calloc(strlen(dev_file) + 1, sizeof(char)); strcpy(infos[num_gpus].i2c_dev_path, dev_file); num_gpus++; @@ -111,12 +117,18 @@ char *read_nvidia_pci_address(char *device_path) FILE *fp = fopen(file_path, "r"); - if (fp == NULL) + if (fp == NULL) { + free(ret); return NULL; + } fscanf(fp, "NVIDIA i2c adapter %*u at %16s", ret); - fclose(fp); + if (strlen(ret) == 0) { + free(ret); + return NULL; + } + return ret; } diff --git a/evga-card.h b/evga-card.h index 6a0569c..f8a10d3 100644 --- a/evga-card.h +++ b/evga-card.h @@ -84,7 +84,7 @@ struct card_info { char *card_name; char *pci_id; char *i2c_dev_path; - int fd; + int i2c_fd; }; struct gpu_pci_info {