Commit 21647677 authored by Koichiro Den's avatar Koichiro Den Committed by Bjorn Helgaas
Browse files

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



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 to become confusing, since the failure may
leave room for the next subrange mapping test to pass.

Fix this by restoring the original BAR mapping when preparation of the
subrange mapping fails, so that no side effect remains regardless of the
test success or failure.

Fixes: 6c5e6101 ("PCI: endpoint: pci-epf-test: Add BAR subrange mapping test support")
Reported-by: default avatarChristian Bruel <christian.bruel@foss.st.com>
Closes: https://lore.kernel.org/linux-pci/b2b03ebe-9482-4a13-b22f-7b44da096eed@foss.st.com/


Signed-off-by: default avatarKoichiro Den <den@valinux.co.jp>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Tested-by: default avatarChristian Bruel <christian.bruel@foss.st.com>
Reviewed-by: default avatarNiklas Cassel <cassel@kernel.org>
Reviewed-by: default avatarManivannan Sadhasivam <mani@kernel.org>
Link: https://patch.msgid.link/20260316140225.1481658-1-den@valinux.co.jp
parent ee226656
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -894,6 +894,11 @@ static void pci_epf_test_bar_subrange_setup(struct pci_epf_test *epf_test,
		dev_err(&epf->dev, "pci_epc_set_bar() failed: %d\n", ret);
		bar->submap = old_submap;
		bar->num_submap = old_nsub;
		ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, bar);
		if (ret)
			dev_warn(&epf->dev, "Failed to restore the original BAR mapping: %d\n",
				 ret);

		kfree(submap);
		goto err;
	}