[PATCH 2/2] cxl/core/regs: Check return value of DVSEC register locator reads

From: Richard Cheng

Date: Sun Jun 07 2026 - 03:03:21 EST


__cxl_find_regblock_instance() reads the CXL Register Locator DVSEC via
pci_read_config_dword() but ignores the return value. On a failed config
read the raw accessor leaves PCI_ERROR_RESPONSE (~0) in the destination,
so the code computes a huge regblock count and decodes register block
addresses from garbage instead of detecting the failure.

Check the return value and convert the positive PCIBIOS_* status to a
negative errno with pcibios_err_to_errno() on the error paths.

Fixes: 303ebc1b1741 ("cxl/acpi: Map component registers for Root Ports")
Signed-off-by: Richard Cheng <icheng@xxxxxxxxxx>
---
drivers/cxl/core/regs.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
index 93710cf4f0a6..bbb1c278c4d8 100644
--- a/drivers/cxl/core/regs.c
+++ b/drivers/cxl/core/regs.c
@@ -303,7 +303,7 @@ static int __cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_ty
{
u32 regloc_size, regblocks;
int instance = 0;
- int regloc, i;
+ int regloc, i, rc;

*map = (struct cxl_register_map) {
.host = &pdev->dev,
@@ -315,7 +315,9 @@ static int __cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_ty
if (!regloc)
return -ENXIO;

- pci_read_config_dword(pdev, regloc + PCI_DVSEC_HEADER1, &regloc_size);
+ rc = pci_read_config_dword(pdev, regloc + PCI_DVSEC_HEADER1, &regloc_size);
+ if (rc)
+ return pcibios_err_to_errno(rc);
regloc_size = PCI_DVSEC_HEADER1_LEN(regloc_size);

regloc += PCI_DVSEC_CXL_REG_LOCATOR_BLOCK1;
@@ -324,8 +326,12 @@ static int __cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_ty
for (i = 0; i < regblocks; i++, regloc += 8) {
u32 reg_lo, reg_hi;

- pci_read_config_dword(pdev, regloc, &reg_lo);
- pci_read_config_dword(pdev, regloc + 4, &reg_hi);
+ rc = pci_read_config_dword(pdev, regloc, &reg_lo);
+ if (rc)
+ return pcibios_err_to_errno(rc);
+ rc = pci_read_config_dword(pdev, regloc + 4, &reg_hi);
+ if (rc)
+ return pcibios_err_to_errno(rc);

if (!cxl_decode_regblock(pdev, reg_lo, reg_hi, map))
continue;
--
2.43.0