* [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge()
@ 2025-02-25 2:14 Ma Ke
2025-02-27 22:01 ` Bjorn Helgaas
0 siblings, 1 reply; 4+ messages in thread
From: Ma Ke @ 2025-02-25 2:14 UTC (permalink / raw)
To: bhelgaas, arnd, treding; +Cc: linux-pci, linux-kernel, akpm, Ma Ke, stable
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>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge()
2025-02-25 2:14 Ma Ke
@ 2025-02-27 22:01 ` Bjorn Helgaas
0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2025-02-27 22:01 UTC (permalink / raw)
To: Ma Ke; +Cc: bhelgaas, arnd, treding, linux-pci, linux-kernel, akpm, stable
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge()
@ 2025-03-03 7:21 Ma Ke
2025-03-03 7:42 ` Krzysztof Wilczyński
0 siblings, 1 reply; 4+ messages in thread
From: Ma Ke @ 2025-03-03 7:21 UTC (permalink / raw)
To: bhelgaas, treding, arnd; +Cc: linux-pci, linux-kernel, akpm, Ma Ke, stable
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>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge()
2025-03-03 7:21 [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge() Ma Ke
@ 2025-03-03 7:42 ` Krzysztof Wilczyński
0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Wilczyński @ 2025-03-03 7:42 UTC (permalink / raw)
To: Ma Ke; +Cc: bhelgaas, treding, arnd, linux-pci, linux-kernel, akpm, stable
Hello,
> 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.
Bjorn took this already, see:
https://lore.kernel.org/linux-pci/20250227220124.GA19560@bhelgaas
That said, you need to ease on the resends a bit. We track your patches
and we will get to these eventually. Please relax a bit, and perhaps focus
your energy here on offering code reviews for other changes, which is
always a great thing to do and helps us a lot. :)
Thank you!
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-03 7:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 7:21 [PATCH v2 RESEND] PCI: fix reference leak in pci_register_host_bridge() Ma Ke
2025-03-03 7:42 ` Krzysztof Wilczyński
-- strict thread matches above, loose matches on Subject: below --
2025-02-25 2:14 Ma Ke
2025-02-27 22:01 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox