]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: endpoint: Add missing NULL check for alloc_workqueue()
authorHaotian Zhang <vulab@iscas.ac.cn>
Mon, 10 Nov 2025 04:04:46 +0000 (12:04 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 29 Dec 2025 16:36:37 +0000 (10:36 -0600)
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: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP")
Fixes: 8b821cf76150 ("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
drivers/pci/endpoint/functions/pci-epf-ntb.c
drivers/pci/endpoint/functions/pci-epf-vntb.c

index 9ea8b57d69d7905063e6f4a0179616d9dd3815f5..a3a588e522e715199b0baec06970b4d836cf2725 100644 (file)
@@ -2126,6 +2126,11 @@ static int __init epf_ntb_init(void)
 
        kpcintb_workqueue = alloc_workqueue("kpcintb",
                                    WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 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);
index a098727f784bd588d5306a1b68a4a64cac942fdb..20a400e834392715275ebbacac6f98eb4b33b63f 100644 (file)
@@ -1653,6 +1653,11 @@ static int __init epf_ntb_init(void)
 
        kpcintb_workqueue = alloc_workqueue("kpcintb",
                                    WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU, 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);