From nobody Sun Feb 8 10:40:03 2026 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1E16299927; Mon, 10 Nov 2025 04:05:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762747503; cv=none; b=q83wEGDhmqyR3c8jA6uB4W19gnw2Ig8AqvUjZYrC1oKaMJp+sdMqtq+25DcEGLy8yyE6k+zNBPEMvsn/00N7RQ7ytSl8UPqasVzZputOIp4FgYysAwl8FKHYM0VMdXglbkMgW1l1/cE4/jYAJjyvlo/keIFkfQNY8VDmNRbYWdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762747503; c=relaxed/simple; bh=RTjKEpIDzrwmwtqOKmKcQDUA+BQVu2gXoDCgg7LL/9Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Izp71vhechtdMUobg0NaA1wwJPLNSfnmghuF01oJTtx3wwM/gN71hq9yDEuDmxgjim86kkY/iPVtUPAPSJ60L9lYixzMEyo07Mc8kQxCUv/FHHGwq08x6zZ860pLoiRwvEjCE87K+7iOp6uqwz5/urkCoRkPXvLqBVfbyWoCqvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from DESKTOP-L0HPE2S (unknown [124.16.141.245]) by APP-05 (Coremail) with SMTP id zQCowAC3f3BjZBFpGlkwAA--.16112S2; Mon, 10 Nov 2025 12:04:52 +0800 (CST) From: Haotian Zhang To: jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com, mani@kernel.org, kwilczynski@kernel.org, kishon@kernel.org, bhelgaas@google.com Cc: ntb@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Haotian Zhang Subject: [PATCH] pci: endpoint: Add missing NULL check for alloc_workqueue() Date: Mon, 10 Nov 2025 12:04:46 +0800 Message-ID: <20251110040446.2065-1-vulab@iscas.ac.cn> X-Mailer: git-send-email 2.50.1.windows.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: zQCowAC3f3BjZBFpGlkwAA--.16112S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFW7Jr18WrW5XF45Cr4xtFb_yoW8uF43pr ZayFy0yrW0qr4UtFZ8Xw4kCFyakanYg34UCF1fuw1avw47WFZYqan5try5tF1DCrWUXw45 ta98X3sFqF1UAr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1x MIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIda VFxhVjvjDU0xZFpf9x0JUd-B_UUUUU= X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiBwwCA2kRR2h3EwAAs5 Content-Type: text/plain; charset="utf-8" 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") Signed-off-by: Haotian Zhang --- drivers/pci/endpoint/functions/pci-epf-ntb.c | 4 ++++ drivers/pci/endpoint/functions/pci-epf-vntb.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/end= point/functions/pci-epf-ntb.c index e01a98e74d21..b3d96a2e3a8c 100644 --- a/drivers/pci/endpoint/functions/pci-epf-ntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c @@ -2126,6 +2126,10 @@ static int __init epf_ntb_init(void) =20 kpcintb_workqueue =3D alloc_workqueue("kpcintb", WQ_MEM_RECLAIM | WQ_HIGHPRI, 0); + if (!kpcintb_workqueue) { + pr_err("Failed to allocate kpcintb workqueue\n"); + return -ENOMEM; + } ret =3D pci_epf_register_driver(&epf_ntb_driver); if (ret) { destroy_workqueue(kpcintb_workqueue); diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/en= dpoint/functions/pci-epf-vntb.c index 83e9ab10f9c4..79800f1fecc3 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -1534,6 +1534,10 @@ static int __init epf_ntb_init(void) =20 kpcintb_workqueue =3D alloc_workqueue("kpcintb", WQ_MEM_RECLAIM | WQ_HIGHPRI, 0); + if (!kpcintb_workqueue) { + pr_err("Failed to allocate kpcintb workqueue\n"); + return -ENOMEM; + } ret =3D pci_epf_register_driver(&epf_ntb_driver); if (ret) { destroy_workqueue(kpcintb_workqueue); --=20 2.50.1.windows.1