Skip to contentSkip to conversation

pci: endpoint: Add missing NULL check for alloc_workqueue()

PATCH Applied Haotian Zhang 3 participants 3 messages Nov 10, 2025 – Dec 18, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: endpoint: Add missing NULL check for alloc_workqueue()

The alloc_workqueue() function can return NULL on memory allocation failure. Without proper error checking, this leads to a NULL pointer dereference when queue_work() is later called with the NULL workqueue pointer in epf_ntb_epc_init().

Add a NULL check immediately after alloc_workqueue() and return -ENOMEM on failure to prevent the driver from loading with an invalid workqueue pointer.

Fixes e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP")
Fixes 8b821cf76150 ("PCI: endpoint: Add EP function driver to provide NTB functionality")
---
 drivers/pci/endpoint/functions/pci-epf-ntb.c  | 4 ++++
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/pci/endpoint/functions/pci-epf-ntb.c +4 -0
index e01a98e74d21..b3d96a2e3a8c 100644
@@ -2126,6 +2126,10 @@ static int __init epf_ntb_init(void)
 
 	kpcintb_workqueue = alloc_workqueue("kpcintb", WQ_MEM_RECLAIM |
 					    WQ_HIGHPRI, 0);
+	if (!kpcintb_workqueue) {
+		pr_err("Failed to allocate kpcintb workqueue\n");
+		return -ENOMEM;
+	}
 	ret = pci_epf_register_driver(&epf_ntb_driver);
 	if (ret) {
 		destroy_workqueue(kpcintb_workqueue);
drivers/pci/endpoint/functions/pci-epf-vntb.c +4 -0
index 83e9ab10f9c4..79800f1fecc3 100644
@@ -1534,6 +1534,10 @@ static int __init epf_ntb_init(void)
 
 	kpcintb_workqueue = alloc_workqueue("kpcintb", WQ_MEM_RECLAIM |
 					    WQ_HIGHPRI, 0);
+	if (!kpcintb_workqueue) {
+		pr_err("Failed to allocate kpcintb workqueue\n");
+		return -ENOMEM;
+	}
 	ret = pci_epf_register_driver(&epf_ntb_driver);
 	if (ret) {
 		destroy_workqueue(kpcintb_workqueue);
Signature · 1 line
2.50.1.windows.1
#1 lore raw
Quoted 22 lines · Haotian Zhang

The alloc_workqueue() function can return NULL on memory allocation failure. Without proper error checking, this leads to a NULL pointer dereference when queue_work() is later called with the NULL workqueue pointer in epf_ntb_epc_init().

Add a NULL check immediately after alloc_workqueue() and return -ENOMEM on failure to prevent the driver from loading with an invalid workqueue pointer.

Fixes e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP")
Fixes 8b821cf76150 ("PCI: endpoint: Add EP function driver to provide NTB functionality")
---
 drivers/pci/endpoint/functions/pci-epf-ntb.c  | 4 ++++
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/pci/endpoint/functions/pci-epf-ntb.c +0 -0
index e01a98e74d21..b3d96a2e3a8c 100644

drivers/pci/endpoint/functions/pci-epf-ntb.c static int __init epf_ntb_init(void) · line 2132

Quoted 7 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c +4 -0
@@ -2126,6 +2126,10 @@ static int __init epf_ntb_init(void)
 
 	kpcintb_workqueue = alloc_workqueue("kpcintb", WQ_MEM_RECLAIM |
 					    WQ_HIGHPRI, 0);
+	if (!kpcintb_workqueue) {
+		pr_err("Failed to allocate kpcintb workqueue\n");
+		return -ENOMEM;
+	}

Can we direct use system_highpri_wq?

Frank Li

Quoted 21 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c +0 -0
 	ret = pci_epf_register_driver(&epf_ntb_driver);
 	if (ret) {
 		destroy_workqueue(kpcintb_workqueue);
drivers/pci/endpoint/functions/pci-epf-vntb.c +4 -1
index 83e9ab10f9c4..79800f1fecc3 100644
@@ -1534,6 +1534,10 @@ static int __init epf_ntb_init(void)
 
 	kpcintb_workqueue = alloc_workqueue("kpcintb", WQ_MEM_RECLAIM |
 					    WQ_HIGHPRI, 0);
+	if (!kpcintb_workqueue) {
+		pr_err("Failed to allocate kpcintb workqueue\n");
+		return -ENOMEM;
+	}
 	ret = pci_epf_register_driver(&epf_ntb_driver);
 	if (ret) {
 		destroy_workqueue(kpcintb_workqueue);
--

2.50.1.windows.1

#2 lore raw
In reply to Haotian Zhang
Quoted 10 lines · Haotian Zhang

The alloc_workqueue() function can return NULL on memory allocation failure. Without proper error checking, this leads to a NULL pointer dereference when queue_work() is later called with the NULL workqueue pointer in epf_ntb_epc_init().

Add a NULL check immediately after alloc_workqueue() and return -ENOMEM on failure to prevent the driver from loading with an invalid workqueue pointer.

[...]

Applied, thanks!

[1/1] pci: endpoint: Add missing NULL check for alloc_workqueue()

      commit: 0a19a6d9ed65ef7df845c32befa994e45620c12d

Best regards,

Signature · 1 line
Manivannan Sadhasivam <[email protected]>