Ensure pci bus ID is lower case

The PCI Bus ID returned by NVML is upper case and results in the following error:

error getting PCI device class for device:
failed to construct PCI device:
unable to read PCI device vendor id for 0000:0A:00.0:
open /sys/bus/pci/devices/0000:0A:00.0/vendor:
no such file or directory

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-11-16 12:12:04 +01:00
parent 9110850748
commit fa5d0408ce

View File

@ -224,7 +224,7 @@ func (d *device) getClass() (Class, error) {
} }
bytes = append(bytes, byte(b)) bytes = append(bytes, byte(b))
} }
id := string(bytes) id := strings.ToLower(string(bytes))
if id != "0000" { if id != "0000" {
id = strings.TrimPrefix(id, "0000") id = strings.TrimPrefix(id, "0000")
@ -232,7 +232,7 @@ func (d *device) getClass() (Class, error) {
device, err := nvpci.New().GetGPUByPciBusID(id) device, err := nvpci.New().GetGPUByPciBusID(id)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to construct PCI device: %v", ret) return 0, fmt.Errorf("failed to construct PCI device: %v", err)
} }
return Class(device.Class), nil return Class(device.Class), nil