Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Niklas Cassel" <cassel@kernel.org>,
	"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Sasha Levin" <sashal@kernel.org>,
	kw@linux.com, gregkh@linuxfoundation.org,
	linux-pci@vger.kernel.org
Subject: [PATCH AUTOSEL 6.14 214/642] misc: pci_endpoint_test: Give disabled BARs a distinct error code
Date: Mon,  5 May 2025 18:07:10 -0400	[thread overview]
Message-ID: <20250505221419.2672473-214-sashal@kernel.org> (raw)
In-Reply-To: <20250505221419.2672473-1-sashal@kernel.org>

From: Niklas Cassel <cassel@kernel.org>

[ 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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 4c0f37ad0281b..8a7e860c06812 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -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;
 
-- 
2.39.5


  parent reply	other threads:[~2025-05-05 22:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250505221419.2672473-1-sashal@kernel.org>
2025-05-05 22:03 ` [PATCH AUTOSEL 6.14 016/642] iommufd: Extend IOMMU_GET_HW_INFO to report PASID capability Sasha Levin
2025-05-05 22:04 ` [PATCH AUTOSEL 6.14 052/642] PCI: dwc: ep: Ensure proper iteration over outbound map windows Sasha Levin
2025-05-05 22:04 ` [PATCH AUTOSEL 6.14 055/642] PCI: xilinx-cpm: Add cpm_csr register mapping for CPM5_HOST1 variant Sasha Levin
2025-05-05 22:04 ` [PATCH AUTOSEL 6.14 063/642] PCI: vmd: Disable MSI remapping bypass under Xen Sasha Levin
2025-05-05 22:05 ` [PATCH AUTOSEL 6.14 128/642] PCI: dwc: Use resource start as ioremap() input in dw_pcie_pme_turn_off() Sasha Levin
2025-05-05 22:07 ` [PATCH AUTOSEL 6.14 213/642] PCI: endpoint: pci-epf-test: Fix double free that causes kernel to oops Sasha Levin
2025-05-05 22:07 ` Sasha Levin [this message]
2025-05-05 22:07 ` [PATCH AUTOSEL 6.14 215/642] selftests: pci_endpoint: Skip disabled BARs Sasha Levin
2025-05-05 22:08 ` [PATCH AUTOSEL 6.14 293/642] PCI: brcmstb: Expand inbound window size up to 64GB Sasha Levin
2025-05-05 22:08 ` [PATCH AUTOSEL 6.14 294/642] PCI: brcmstb: Add a softdep to MIP MSI-X driver Sasha Levin
2025-05-05 22:09 ` [PATCH AUTOSEL 6.14 348/642] x86/kaslr: Reduce KASLR entropy on most x86 systems Sasha Levin
2025-05-05 22:09 ` [PATCH AUTOSEL 6.14 362/642] PCI: epf-mhi: Update device ID for SA8775P Sasha Levin
2025-05-05 22:09 ` [PATCH AUTOSEL 6.14 382/642] PCI/pwrctrl: Move pci_pwrctrl_unregister() to pci_destroy_dev() Sasha Levin
2025-05-06  8:06   ` Lukas Wunner
2025-05-10  6:31     ` Manivannan Sadhasivam
2025-05-20 14:12       ` Sasha Levin
2025-05-05 22:10 ` [PATCH AUTOSEL 6.14 397/642] PCI: Fix old_size lower bound in calculate_iosize() too Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250505221419.2672473-214-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kw@linux.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox