Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	<bhelgaas@google.com>, Rob Herring <robh@kernel.org>
Subject: Re: [PATCH -next 1/3] PCI: fix double put_device() in error case in pci_create_root_bus()
Date: Sat, 27 Aug 2022 17:15:25 +0800	[thread overview]
Message-ID: <e901ef8c-e580-ba89-f161-bd0e6959483f@huawei.com> (raw)
In-Reply-To: <20220826211401.GA2959769@bhelgaas>

Hi,

On 2022/8/27 5:14, Bjorn Helgaas wrote:
> [+cc Rob]
>
> On Thu, Aug 25, 2022 at 08:27:51PM +0800, Yang Yingliang wrote:
>> If device_add() fails in pci_register_host_bridge(), the brigde device will
>> be put once, and it will be put again in error path of pci_create_root_bus().
>> Move the put_device() from pci_create_root_bus() to pci_register_host_bridge()
>> to fix this problem. And use device_unregister() instead of del_device() and
>> put_device().
> s/brigde/bridge/
>
>> Fixes: 9885440b16b8 ("PCI: Fix pci_host_bridge struct device release/free handling")
> If you're fixing a commit from somebody else, please always cc: the
> author because the author can help review the change.
OK.
>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/pci/probe.c | 8 ++------
>>   1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
>> index c5286b027f00..e500eb9d6468 100644
>> --- a/drivers/pci/probe.c
>> +++ b/drivers/pci/probe.c
>> @@ -1027,7 +1027,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
>>   
>>   unregister:
>>   	put_device(&bridge->dev);
>> -	device_del(&bridge->dev);
>> +	device_unregister(&bridge->dev);
> I don't understand this part.  device_unregister() looks like this:
>
>    void device_unregister(struct device *dev)
>    {
>      device_del(dev);
>      put_device(dev);
>    }
>
> So this calls put_device(&bridge->dev) twice, doesn't it?
>
> The "unregister" label looks poorly named.  We only get there if
> device_register() *failed*.  We shouldn't need to unregister anything
> in that case.
If it goes to the 'unregister' label, the bridge->dev has been register 
sucessfully (device_initialize() called from pci_alloc_host_bridge()
and device_add() called from pci_register_host_bridge()), so it need be 
unregister, and another put_device() is for decreasing
refcount of 'bus->bridge'.

Thanks,
Yang
>
>>   free:
>>   	kfree(bus);
>> @@ -3037,13 +3037,9 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
>>   
>>   	error = pci_register_host_bridge(bridge);
>>   	if (error < 0)
>> -		goto err_out;
>> +		return NULL;
>>   
>>   	return bridge->bus;
>> -
>> -err_out:
>> -	put_device(&bridge->dev);
>> -	return NULL;
> This part looks right to me.  The get_device() is in
> pci_register_host_bridge(), and if pci_register_host_bridge() returns
> failure, I think it should first do the corresponding put_device().
>
>>   }
>>   EXPORT_SYMBOL_GPL(pci_create_root_bus);
>>   
>> -- 
>> 2.25.1
>>
> .

      reply	other threads:[~2022-08-27  9:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25 12:27 [PATCH -next 1/3] PCI: fix double put_device() in error case in pci_create_root_bus() Yang Yingliang
2022-08-25 12:27 ` [PATCH -next 2/3] PCI: fix possible memory leak in error case in pci_register_host_bridge() Yang Yingliang
2022-08-26 22:38   ` Bjorn Helgaas
2022-08-27  9:29     ` Yang Yingliang
2022-08-25 12:27 ` [PATCH -next 3/3] PCI: fix handle error case in pci_alloc_child_bus() Yang Yingliang
2022-08-26 21:14 ` [PATCH -next 1/3] PCI: fix double put_device() in error case in pci_create_root_bus() Bjorn Helgaas
2022-08-27  9:15   ` Yang Yingliang [this message]

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=e901ef8c-e580-ba89-f161-bd0e6959483f@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=helgaas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=robh@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