Re: [PATCH] PCI: endpoint: pci-epf-vntb: Check pci_epc_get_features() return value
Niklas Cassel <[email protected]> Tue, 24 Feb 2026 14:38:33 +0100
| Newsgroups | dev.linux.lists.ntb,org.kernel.vger.linux-pci |
|---|---|
| Message-ID | <aZ2p08thDzZdSdNc@ryzen> |
On Tue, Feb 24, 2026 at 05:31:03AM -0800, Alok Tiwari wrote: > 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 <[email protected]> I think a better solution is to do like pci-epf-test.c, which calls pci_epc_get_features() once in .bind() and if it fails, it fails bind(), if it returns non-NULL, it caches the result: https://github.com/torvalds/linux/blob/v6.19/drivers/pci/endpoint/functions/pci-epf-test.c#L1112-L1123 That way, all other functions do not need to NULL check pci_epc_get_features(). (Instead it can use the cached value) pci-epf-vntb.c should probably do something similar to avoid sprinkling NULL checks all over pci-epf-vntb.c. And, if there are any existing if (!epc_features) return -EINVAL; they can be removed once you've added the check in .bind(). Kind regards, Niklas