Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of PCI domains longer than 4 digits #373

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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
11 changes: 5 additions & 6 deletions pkg/pci/address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var (
regexAddress *regexp.Regexp = regexp.MustCompile(
`^(([0-9a-f]{0,4}):)?([0-9a-f]{2}):([0-9a-f]{2})\.([0-9a-f]{1})$`,
`^((1?[0-9a-f]{0,4}):)?([0-9a-f]{2}):([0-9a-f]{2})\.([0-9a-f]{1})$`,
)
)

Expand All @@ -30,12 +30,11 @@ func (addr *Address) String() string {
return addr.Domain + ":" + addr.Bus + ":" + addr.Device + "." + addr.Function
}

// FromString returns an Address struct from an ddress string in either
// $BUS:$DEVICE.$FUNCTION (BDF) format or it can be a full PCI address that
// includes the 4-digit $DOMAIN information as well:
// $DOMAIN:$BUS:$DEVICE.$FUNCTION.
// FromString returns [Address] from an address string in either
// $BUS:$DEVICE.$FUNCTION (BDF) format or a full PCI address that
// includes the domain: $DOMAIN:$BUS:$DEVICE.$FUNCTION.
//
// Returns "" if the address string wasn't a valid PCI address.
// If the address string isn't a valid PCI address, then nil is returned.
func FromString(address string) *Address {
addrLowered := strings.ToLower(address)
matches := regexAddress.FindStringSubmatch(addrLowered)
Expand Down
10 changes: 10 additions & 0 deletions pkg/pci/address/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func TestPCIAddressFromString(t *testing.T) {
Function: "a",
},
},
{
// PCI-X / PCI Express extensions may use 5-digit domain
addrStr: "10000:03:00.A",
expected: &pciaddr.Address{
Domain: "10000",
Bus: "03",
Device: "00",
Function: "a",
},
},
}
for x, test := range tests {
got := pciaddr.FromString(test.addrStr)
Expand Down
Loading