mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Haotian Zhang <vulab@iscas.ac.cn>
Cc: jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com,
	mani@kernel.org, kwilczynski@kernel.org, kishon@kernel.org,
	bhelgaas@google.com, ntb@lists.linux.dev,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pci: endpoint: Add missing NULL check for alloc_workqueue()
Date: Mon, 10 Nov 2025 14:51:12 -0500	[thread overview]
Message-ID: <aRJCMEUdjxh5K2UG@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20251110040446.2065-1-vulab@iscas.ac.cn>

On Mon, Nov 10, 2025 at 12:04:46PM +0800, Haotian Zhang wrote:
> 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 <vulab@iscas.ac.cn>
> ---
>  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/endpoint/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)
>
>  	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
>  	ret = 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/endpoint/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)
>
>  	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
>

  reply	other threads:[~2025-11-10 19:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10  4:04 Haotian Zhang
2025-11-10 19:51 ` Frank Li [this message]
2025-12-18  7:12 ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aRJCMEUdjxh5K2UG@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=allenbh@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=dave.jiang@intel.com \
    --cc=jdmason@kudzu.us \
    --cc=kishon@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=ntb@lists.linux.dev \
    --cc=vulab@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®