[PATCH] PCI: endpoint: pci-epf-test: Roll back BAR mapping when subrange setup fails

Koichiro Den den at valinux.co.jp
Sat Mar 14 14:58:04 AEDT 2026


When the BAR subrange mapping test on DWC-based platforms fails due to
insufficient free inbound iATU regions,
pci_epf_test_bar_subrange_setup() returns an error (-ENOSPC) but does
not restore the original BAR mapping. This causes subsequent test runs
become confusing, since the failure leaves a room for the next subrange
mapping test to pass.

Fix this by restoring the original BAR mapping when preparation of the
subrange mapping fails.

Fixes: 6c5e6101423b ("PCI: endpoint: pci-epf-test: Add BAR subrange mapping test support")
Reported-by: Christian Bruel <christian.bruel at foss.st.com>
Signed-off-by: Koichiro Den <den at valinux.co.jp>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 582938b7b4f1..0e5958088b8f 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -891,12 +891,15 @@ static void pci_epf_test_bar_subrange_setup(struct pci_epf_test *epf_test,

        ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, bar);
        if (ret) {
                dev_err(&epf->dev, "pci_epc_set_bar() failed: %d\n", ret);
                bar->submap = old_submap;
                bar->num_submap = old_nsub;
+               if (pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, bar))
+                       dev_warn(&epf->dev, "failed to roll back\n");
+
                kfree(submap);
                goto err;
        }
        kfree(old_submap);

        /*
--
2.51.0

[---8<---]

I'd appreciate it if you could test this. Or, if I'm still missing the point of
your report, please let me know.

Best regards,
Koichiro

> 
> thank you
> 
> Christian


More information about the Linuxppc-dev mailing list