public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Ma Ke <make24@iscas.ac.cn>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ma Ke <make24@iscas.ac.cn>
Subject: [PATCH] PCI: fix reference leak in pci_alloc_child_bus()
Date: Tue,  7 Jan 2025 19:07:47 +0800	[thread overview]
Message-ID: <20250107110747.860952-1-make24@iscas.ac.cn> (raw)

When device_register(&child->dev) failed, calling put_device() to
explicitly release child->dev. Otherwise, it could cause double free
problem.

Found by code review.

Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/pci/probe.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 2e81ab0f5a25..a61070ce5f88 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1174,7 +1174,10 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
 add_dev:
 	pci_set_bus_msi_domain(child);
 	ret = device_register(&child->dev);
-	WARN_ON(ret < 0);
+	if (WARN_ON(ret < 0)) {
+		put_device(&child->dev);
+		return ERR_PTR(ret);
+	}
 
 	pcibios_add_bus(child);
 
-- 
2.25.1


             reply	other threads:[~2025-01-07 11:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 11:07 Ma Ke [this message]
2025-01-07 18:48 ` [PATCH] PCI: fix reference leak in pci_alloc_child_bus() Christophe JAILLET
  -- strict thread matches above, loose matches on Subject: below --
2024-12-17  3:54 Ma Ke
2024-12-18 15:12 ` Ilpo Järvinen
2024-12-19  1:39   ` Ma Ke

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=20250107110747.860952-1-make24@iscas.ac.cn \
    --to=make24@iscas.ac.cn \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.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