linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: fix double put_device() in error case in pci_create_root_bus()
@ 2022-10-18  3:51 Yang Yingliang
  2022-10-18 10:38 ` Thierry Reding
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Yingliang @ 2022-10-18  3:51 UTC (permalink / raw)
  To: linux-pci; +Cc: bhelgaas, arnd, treding, yangyingliang

If device_add() fails in pci_register_host_bridge(), the bridge device will
be put once, and it will be put again in error path of pci_create_root_bus().
Fix this by removing put_device() after device_add() is failed.

Fixes: 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/pci/probe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b66fa42c4b1f..f61754d76aa7 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -926,10 +926,8 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
 	/* Temporarily move resources off the list */
 	list_splice_init(&bridge->windows, &resources);
 	err = device_add(&bridge->dev);
-	if (err) {
-		put_device(&bridge->dev);
+	if (err)
 		goto free;
-	}
 	bus->bridge = get_device(&bridge->dev);
 	device_enable_async_suspend(bus->bridge);
 	pci_set_bus_of_node(bus);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: fix double put_device() in error case in pci_create_root_bus()
  2022-10-18  3:51 [PATCH] PCI: fix double put_device() in error case in pci_create_root_bus() Yang Yingliang
@ 2022-10-18 10:38 ` Thierry Reding
  2022-11-23  7:42   ` Yang Yingliang
  0 siblings, 1 reply; 3+ messages in thread
From: Thierry Reding @ 2022-10-18 10:38 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-pci, bhelgaas, arnd

[-- Attachment #1: Type: text/plain, Size: 720 bytes --]

On Tue, Oct 18, 2022 at 11:51:34AM +0800, Yang Yingliang wrote:
> If device_add() fails in pci_register_host_bridge(), the bridge device will
> be put once, and it will be put again in error path of pci_create_root_bus().
> Fix this by removing put_device() after device_add() is failed.
> 
> Fixes: 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/pci/probe.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Seems fine. All callers, as far as I can tell, of this end up invoking
pci_free_host_bridge() which does the corresponding put_device() itself:

Reviewed-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: fix double put_device() in error case in pci_create_root_bus()
  2022-10-18 10:38 ` Thierry Reding
@ 2022-11-23  7:42   ` Yang Yingliang
  0 siblings, 0 replies; 3+ messages in thread
From: Yang Yingliang @ 2022-11-23  7:42 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-pci, bhelgaas, arnd, yangyingliang

Hi Helgaas,

On 2022/10/18 18:38, Thierry Reding wrote:
> On Tue, Oct 18, 2022 at 11:51:34AM +0800, Yang Yingliang wrote:
>> If device_add() fails in pci_register_host_bridge(), the bridge device will
>> be put once, and it will be put again in error path of pci_create_root_bus().
>> Fix this by removing put_device() after device_add() is failed.
I think it's a obvious problem.
Is this patch look good to you or any suggestion?

Thanks,
Yang
>>
>> Fixes: 37d6a0a6f470 ("PCI: Add pci_register_host_bridge() interface")
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/pci/probe.c | 4 +---
>>   1 file changed, 1 insertion(+), 3 deletions(-)
> Seems fine. All callers, as far as I can tell, of this end up invoking
> pci_free_host_bridge() which does the corresponding put_device() itself:
>
> Reviewed-by: Thierry Reding <treding@nvidia.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-23  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18  3:51 [PATCH] PCI: fix double put_device() in error case in pci_create_root_bus() Yang Yingliang
2022-10-18 10:38 ` Thierry Reding
2022-11-23  7:42   ` Yang Yingliang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).