Skip to content

Commit

Permalink
fix: get wrong pci address
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Yu <jack.yu@suse.com>
  • Loading branch information
Yu-Jack committed Jun 25, 2024
1 parent 24f6b09 commit 3157013
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/deviceplugins/usb_device_plugin_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ func WalkUSBDevices() (map[int][]*USBDevice, error) {
}

func parseUSBSymLinkToPCIAddress(link string) string {
paths := strings.Split(link, "/")
paths := strings.Split(link, "/usb")

if len(paths) < 3 {
if len(paths) < 2 {
return ""
}

pciAddress := paths[len(paths)-3 : len(paths)-2][0]
return pciAddress
paths = strings.Split(paths[0], "/")

return paths[len(paths)-1]
}

func discoverPluggedUSBDevices() *LocalDevices {
Expand Down
8 changes: 8 additions & 0 deletions pkg/deviceplugins/usb_device_plugin_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func Test_parseUSBSymLinkToPCIAddress(t *testing.T) {
symLink: "../../../devices/pci0000:00/0000:00:02.2/0000:04:00.0/usb3/3-1",
expected: "0000:04:00.0",
},
{
symLink: "devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:01.0/usb2/2-4/2-4.3",
expected: "0000:02:01.0",
},
{
symLink: "devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:01.0/usb2/2-4/2-4.3/2-4.3:1.",
expected: "0000:02:01.0",
},
}

for _, testcase := range testcases {
Expand Down

0 comments on commit 3157013

Please sign in to comment.