Skip to content

Commit

Permalink
off by one error on pci address detection
Browse files Browse the repository at this point in the history
Change-Id: I588f98a839fc1085fad920254613ee83c3315e65
  • Loading branch information
aojea committed Dec 15, 2024
1 parent 211acb5 commit 9a28f3e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/inventory/sysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,19 @@ func bdfAddress(ifName string, path string) (*pciAddress, error) {
// PCI domain: 0000 Bus: 00 Device: 04 Function: 0
sysfsPath := realpath(ifName, path)
bfd := strings.Split(sysfsPath, "/")
if len(bfd) < 4 {
if len(bfd) < 5 {
return nil, fmt.Errorf("could not find corresponding PCI address: %v", bfd)
}

pci := strings.Split(bfd[3], ":")
klog.V(4).Infof("pci address: %s", bfd[4])
pci := strings.Split(bfd[4], ":")
// Simple BDF notation
switch len(pci) {
case 2:
address.bus = pci[0]
f := strings.Split(pci[1], ".")
if len(f) != 2 {
return nil, fmt.Errorf("could not find corresponding PCI device and function: %s", pci[1])
return nil, fmt.Errorf("could not find corresponding PCI device and function: %v", pci)
}
address.device = f[0]
address.function = f[1]
Expand All @@ -154,7 +155,7 @@ func bdfAddress(ifName string, path string) (*pciAddress, error) {
address.bus = pci[1]
f := strings.Split(pci[2], ".")
if len(f) != 2 {
return nil, fmt.Errorf("could not find corresponding PCI device and function: %s", pci[2])
return nil, fmt.Errorf("could not find corresponding PCI device and function: %v", pci)
}
address.device = f[0]
address.function = f[1]
Expand Down

0 comments on commit 9a28f3e

Please sign in to comment.