Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: endpoint: pci-epf-vntb: Check pci_epc_get_features() return value
@ 2026-02-24 13:31 Alok Tiwari
  2026-02-24 13:38 ` Niklas Cassel
  2026-02-25  5:21 ` Koichiro Den
  0 siblings, 2 replies; 3+ messages in thread
From: Alok Tiwari @ 2026-02-24 13:31 UTC (permalink / raw)
  To: den, cassel, jdmason, dave.jiang, allenbh, mani, kwilczynski,
	kishon, bhelgaas, ntb, linux-pci
  Cc: alok.a.tiwarilinux, alok.a.tiwari

pci_epc_get_features() may return NULL for invalid function numbers or
if the EPC driver does not provide feature information. Other EPF drivers
such as pci-epf-ntb.c and pci-epf-test.c already handle this case.

Add a defensive NULL check to avoid a potential NULL pointer dereference.

No functional change intended.

Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index 20a400e83439..93943e4497a6 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -438,6 +438,8 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb)
 	const struct pci_epc_features *epc_features = pci_epc_get_features(epf->epc,
 								epf->func_no,
 								epf->vfunc_no);
+	if (!epc_features)
+		return -EINVAL;
 	barno = ntb->epf_ntb_bar[BAR_CONFIG];
 	spad_count = ntb->spad_count;
 
@@ -489,6 +491,8 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb)
 	dev = &ntb->epf->dev;
 
 	epc_features = pci_epc_get_features(ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no);
+	if (!epc_features)
+		return -EINVAL;
 
 	if (!(epc_features->msix_capable || epc_features->msi_capable)) {
 		dev_err(dev, "MSI or MSI-X is required for doorbell\n");
@@ -624,6 +628,8 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
 	epc_features = pci_epc_get_features(ntb->epf->epc,
 					    ntb->epf->func_no,
 					    ntb->epf->vfunc_no);
+	if (!epc_features)
+		return -EINVAL;
 	barno = ntb->epf_ntb_bar[BAR_DB];
 	epf_bar = &ntb->epf->bar[barno];
 
@@ -852,6 +858,8 @@ static int epf_ntb_init_epc_bar(struct epf_ntb *ntb)
 	num_mws = ntb->num_mws;
 	dev = &ntb->epf->dev;
 	epc_features = pci_epc_get_features(ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no);
+	if (!epc_features)
+		return -EINVAL;
 
 	/* These are required BARs which are mandatory for NTB functionality */
 	for (bar = BAR_CONFIG; bar <= BAR_MW1; bar++) {
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-25  5:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 13:31 [PATCH] PCI: endpoint: pci-epf-vntb: Check pci_epc_get_features() return value Alok Tiwari
2026-02-24 13:38 ` Niklas Cassel
2026-02-25  5:21 ` Koichiro Den

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox