]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
misc: pci_endpoint_test: Give disabled BARs a distinct error code
authorNiklas Cassel <cassel@kernel.org>
Thu, 23 Jan 2025 12:01:48 +0000 (13:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:12:51 +0000 (11:12 +0200)
[ Upstream commit 7e80bbef1d697dbce7a39cfad0df770880fe3f29 ]

The current code returns -ENOMEM if test->bar[barno] is NULL.

There can be two reasons why test->bar[barno] is NULL:

  1) The pci_ioremap_bar() call in pci_endpoint_test_probe() failed.
  2) The BAR was skipped, because it is disabled by the endpoint.

Many PCI endpoint controller drivers will disable all BARs in their
init function. A disabled BAR will have a size of 0.

A PCI endpoint function driver will be able to enable any BAR that
is not marked as BAR_RESERVED (which means that the BAR should not
be touched by the EPF driver).

Thus, perform check if the size is 0, before checking if
test->bar[barno] is NULL, such that we can return different errors.

This will allow the selftests to return SKIP instead of FAIL for
disabled BARs.

Signed-off-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20250123120147.3603409-3-cassel@kernel.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[kwilczynski: commit log]
Signed-off-by: Krzysztof WilczyƄski <kwilczynski@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/misc/pci_endpoint_test.c

index 4c0f37ad0281b1d64976a6969443adf9598d5b06..8a7e860c068126efae4e27c9ef5a7ba08840ba84 100644 (file)
@@ -295,11 +295,13 @@ static int pci_endpoint_test_bar(struct pci_endpoint_test *test,
        struct pci_dev *pdev = test->pdev;
        int buf_size;
 
+       bar_size = pci_resource_len(pdev, barno);
+       if (!bar_size)
+               return -ENODATA;
+
        if (!test->bar[barno])
                return -ENOMEM;
 
-       bar_size = pci_resource_len(pdev, barno);
-
        if (barno == test->test_reg_bar)
                bar_size = 0x4;