From 1ec81622933eb0026f14154cd68640008e76d31d Mon Sep 17 00:00:00 2001 From: Ian Bishop <151477169+ianb-mp@users.noreply.github.com> Date: Thu, 5 Sep 2024 09:24:47 +1000 Subject: [PATCH] Fix parsing of PCI domains longer than 4 digits Signed-off-by: Ian Bishop <151477169+ianb-mp@users.noreply.github.com> --- pkg/pci/address/address.go | 4 ++-- pkg/pci/address/address_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/pci/address/address.go b/pkg/pci/address/address.go index 65e8cca5..660238c2 100644 --- a/pkg/pci/address/address.go +++ b/pkg/pci/address/address.go @@ -13,7 +13,7 @@ import ( var ( regexAddress *regexp.Regexp = regexp.MustCompile( - `^(([0-9a-f]{0,8}):)?([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})$`, ) ) @@ -32,7 +32,7 @@ func (addr *Address) String() string { // 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. +// includes the domain: $DOMAIN:$BUS:$DEVICE.$FUNCTION. // // If the address string isn't a valid PCI address, then nil is returned. func FromString(address string) *Address { diff --git a/pkg/pci/address/address_test.go b/pkg/pci/address/address_test.go index daf0eaa6..54c873e6 100644 --- a/pkg/pci/address/address_test.go +++ b/pkg/pci/address/address_test.go @@ -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)