Skip to content

Commit

Permalink
Fix parsing of PCI domains longer than 4 digits
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bishop <151477169+ianb-mp@users.noreply.github.com>
  • Loading branch information
ianb-mp committed Sep 4, 2024
1 parent 7e3f410 commit 22ffa03
Showing 1 changed file with 5 additions and 6 deletions.
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})$`,
`^(([0-9a-f]{0,8}):)?([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

0 comments on commit 22ffa03

Please sign in to comment.