public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Ma Ke <make24@iscas.ac.cn>
Cc: bhelgaas@google.com, arnd@arndb.de, treding@nvidia.com,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge()
Date: Thu, 27 Feb 2025 16:01:24 -0600	[thread overview]
Message-ID: <20250227220124.GA19560@bhelgaas> (raw)
In-Reply-To: <20250225021440.3130264-1-make24@iscas.ac.cn>

On Tue, Feb 25, 2025 at 10:14:40AM +0800, Ma Ke wrote:
> Once device_register() failed, we should call put_device() to
> decrement reference count for cleanup. Or it could cause memory leak.
> 
> device_register() includes device_add(). As comment of device_add()
> says, 'if device_add() succeeds, you should call device_del() when you
> want to get rid of it. If device_add() has not succeeded, use only
> put_device() to drop the reference count'.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>

Applied to pci/enumeration for v6.15, thanks!

> ---
> Changes in v2:
> - modified the patch description.
> ---
>  drivers/pci/probe.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 246744d8d268..7b1d7ce3a83e 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1018,8 +1018,10 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
>  	name = dev_name(&bus->dev);
>  
>  	err = device_register(&bus->dev);
> -	if (err)
> +	if (err) {
> +		put_device(&bus->dev);
>  		goto unregister;
> +	}
>  
>  	pcibios_add_bus(bus);
>  
> -- 
> 2.25.1
> 

  reply	other threads:[~2025-02-27 22:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25  2:14 [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge() Ma Ke
2025-02-27 22:01 ` Bjorn Helgaas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-03-03  7:21 Ma Ke
2025-03-03  7:42 ` Krzysztof Wilczyński

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=20250227220124.GA19560@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=stable@vger.kernel.org \
    --cc=treding@nvidia.com \
    /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