Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Aadityarangan Shridhar Iyengar <adiyenga@cisco.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Manivannan Sadhasivam <mani@kernel.org>
Subject: Re: [PATCH] PCI/PTM: Fix memory leak in pcie_ptm_create_debugfs() error path
Date: Tue, 13 Jan 2026 12:59:11 -0600	[thread overview]
Message-ID: <20260113185911.GA775194@bhelgaas> (raw)
In-Reply-To: <20260111163650.33168-1-adiyenga@cisco.com>

[+cc Mani, author of 132833405e61]

On Sun, Jan 11, 2026 at 10:06:50PM +0530, Aadityarangan Shridhar Iyengar wrote:
> In pcie_ptm_create_debugfs(), if devm_kasprintf() fails after successfully
> allocating ptm_debugfs with kzalloc(), the function returns NULL without
> freeing the allocated memory, resulting in a memory leak.
> 
> Fix this by adding kfree(ptm_debugfs) before returning NULL in the
> devm_kasprintf() error path.
> 
> This leak is particularly problematic during memory pressure situations
> where devm_kasprintf() is more likely to fail, potentially compounding
> the memory exhaustion issue.
> 
> Fixes: 132833405e61 ("PCI: Add debugfs support for exposing PTM context")
> Signed-off-by: Aadityarangan Shridhar Iyengar <adiyenga@cisco.com>

Applied to pci/ptm for v6.20, thanks!

> ---
>  drivers/pci/pcie/ptm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pcie/ptm.c b/drivers/pci/pcie/ptm.c
> index ed0f9691e7d1..09c0167048a3 100644
> --- a/drivers/pci/pcie/ptm.c
> +++ b/drivers/pci/pcie/ptm.c
> @@ -542,8 +542,10 @@ struct pci_ptm_debugfs *pcie_ptm_create_debugfs(struct device *dev, void *pdata,
>  		return NULL;
>  
>  	dirname = devm_kasprintf(dev, GFP_KERNEL, "pcie_ptm_%s", dev_name(dev));
> -	if (!dirname)
> +	if (!dirname) {
> +		kfree(ptm_debugfs);
>  		return NULL;
> +	}
>  
>  	ptm_debugfs->debugfs = debugfs_create_dir(dirname, NULL);
>  	ptm_debugfs->pdata = pdata;
> -- 
> 2.35.6
> 

  reply	other threads:[~2026-01-13 18:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11 16:36 [PATCH] PCI/PTM: Fix memory leak in pcie_ptm_create_debugfs() error path Aadityarangan Shridhar Iyengar
2026-01-13 18:59 ` Bjorn Helgaas [this message]
2026-01-14  7:28 ` Manivannan Sadhasivam
2026-01-14 16:39   ` Bjorn Helgaas
2026-01-14 16:26 ` [PATCH] PCI/AER: Fix device reference leak in aer_inject() Aadityarangan Shridhar Iyengar
  -- strict thread matches above, loose matches on Subject: below --
2026-01-11 16:30 [PATCH] PCI/PTM: Fix memory leak in pcie_ptm_create_debugfs() error path Aadityarangan Shridhar Iyengar

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=20260113185911.GA775194@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=adiyenga@cisco.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    /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