public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: endpoint: pci-epf-test: Make use of cached 'epc_features' in pci_epf_test_core_init()
@ 2024-04-17 17:17 Manivannan Sadhasivam
  2024-04-17 17:49 ` Niklas Cassel
  0 siblings, 1 reply; 11+ messages in thread
From: Manivannan Sadhasivam @ 2024-04-17 17:17 UTC (permalink / raw)
  To: Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, Dan Carpenter, Manivannan Sadhasivam

Instead of getting the epc_features from pci_epc_get_features() API, use
the cached pci_epf_test::epc_features value to avoid the NULL check. Since
the NULL check is already performed in pci_epf_test_bind(), having one more
check in pci_epf_test_core_init() is redundant and it is not possible to
hit the NULL pointer dereference. This also leads to the following smatch
warning:

drivers/pci/endpoint/functions/pci-epf-test.c:784 pci_epf_test_core_init()
error: we previously assumed 'epc_features' could be null (see line 747)

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-pci/024b5826-7180-4076-ae08-57d2584cca3f@moroto.mountain/
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 977fb79c1567..0d28f413cb07 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -743,11 +743,10 @@ static int pci_epf_test_core_init(struct pci_epf *epf)
 	bool msi_capable = true;
 	int ret;
 
-	epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no);
-	if (epc_features) {
-		msix_capable = epc_features->msix_capable;
-		msi_capable = epc_features->msi_capable;
-	}
+	epc_features = epf_test->epc_features;
+
+	msix_capable = epc_features->msix_capable;
+	msi_capable = epc_features->msi_capable;
 
 	if (epf->vfunc_no <= 1) {
 		ret = pci_epc_write_header(epc, epf->func_no, epf->vfunc_no, header);

---
base-commit: 6e47dcb2ca223211c43c37497836cd9666c70674
change-id: 20240417-pci-epf-test-fix-2209ae22be80

Best regards,
-- 
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>


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

end of thread, other threads:[~2024-04-18  7:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-17 17:17 [PATCH] PCI: endpoint: pci-epf-test: Make use of cached 'epc_features' in pci_epf_test_core_init() Manivannan Sadhasivam
2024-04-17 17:49 ` Niklas Cassel
2024-04-17 17:54   ` Dan Carpenter
2024-04-17 17:54   ` Niklas Cassel
2024-04-18  5:47     ` Manivannan Sadhasivam
2024-04-18  5:43   ` Manivannan Sadhasivam
2024-04-18  6:46     ` Niklas Cassel
2024-04-18  6:53       ` Manivannan Sadhasivam
2024-04-18  7:14         ` Niklas Cassel
2024-04-18  7:30           ` Manivannan Sadhasivam
2024-04-18  7:40             ` Niklas Cassel

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