Skip to content

Commit 03f336a

Browse files
ISCAS-Vulabbjorn-helgaas
authored andcommitted
PCI: endpoint: Add missing NULL check for alloc_workqueue()
alloc_workqueue() can return NULL on memory allocation failure. Without proper error checking, this may lead 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: e35f56b ("PCI: endpoint: Support NTB transfer between RC and EP") Fixes: 8b821cf ("PCI: endpoint: Add EP function driver to provide NTB functionality") Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/20251110040446.2065-1-vulab@iscas.ac.cn
1 parent 0d325cb commit 03f336a

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/pci/endpoint/functions/pci-epf-ntb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,11 @@ static int __init epf_ntb_init(void)
21262126

21272127
kpcintb_workqueue = alloc_workqueue("kpcintb",
21282128
WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 0);
2129+
if (!kpcintb_workqueue) {
2130+
pr_err("Failed to allocate kpcintb workqueue\n");
2131+
return -ENOMEM;
2132+
}
2133+
21292134
ret = pci_epf_register_driver(&epf_ntb_driver);
21302135
if (ret) {
21312136
destroy_workqueue(kpcintb_workqueue);

drivers/pci/endpoint/functions/pci-epf-vntb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,11 @@ static int __init epf_ntb_init(void)
16531653

16541654
kpcintb_workqueue = alloc_workqueue("kpcintb",
16551655
WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 0);
1656+
if (!kpcintb_workqueue) {
1657+
pr_err("Failed to allocate kpcintb workqueue\n");
1658+
return -ENOMEM;
1659+
}
1660+
16561661
ret = pci_epf_register_driver(&epf_ntb_driver);
16571662
if (ret) {
16581663
destroy_workqueue(kpcintb_workqueue);

0 commit comments

Comments
 (0)