mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "liwei (JK)" <liwei728@huawei.com>
To: Su Hui <suhui@nfschina.com>
Cc: <linux-kernel@vger.kernel.org>, <make24@iscas.ac.cn>,
	<bhelgaas@google.com>, <linux-pci@vger.kernel.org>,
	<bobo.shaobowang@huawei.com>, <wangxiongfeng2@huawei.com>
Subject: Re: [PATCH] Revert "PCI: Fix reference leak in pci_register_host_bridge()"
Date: Sat, 12 Apr 2025 11:18:03 +0800	[thread overview]
Message-ID: <c81b43b7-e993-4e9f-ad27-acacd0b85847@huawei.com> (raw)
In-Reply-To: <4a967093-97e2-401f-a0ea-9d7447d518c4@nfschina.com>



在 2025/4/10 19:19, Su Hui 写道:
> On 2025/4/10 11:28, Xiangwei Li wrote:
>> This reverts commit 804443c1f27883926de94c849d91f5b7d7d696e9.
>>
>> The newly added logic incorrectly sets bus_registered to true even when
>> device_register returns an error, this is incorrect.
>>
>> When device_register fails, there is no need to release the reference 
>> count,
> I think you missed some thing about device_register(). This patch is wrong.
> 
> device_register()
>      -> device_initialize()
>                -> kobject_init()
>                      -> kobject_init_internal()
>                          -> kref_init(&kobj->kref);  //set 
> kref->refcount to 1
>                             ^^^^^^^^^^^^^^^^^^^^^
> 
Sorry, I missed the initialization of refcount in device_initialize,
but I’m confused about the branch logic for bus_registered. Why isn’t
free(bus) executed when bus_registered == true? My understanding is
that the kobject_cleanup operation triggered when refcount reaches zero
does not clean up the allocated bus. Could you clarify this further?

Thanks,
Xiangwei Li
> device_register() only  fails when device_add() fails, and 
> kerf->refcount can be 1
> at this time ,  so we need to call put_deivce() to release  memory.
>> and there are no direct error-handling operations following its 
>> execution.
>>
>> Therefore, this patch is meaningless and should be reverted.
>>
>> Fixes: 804443c1f278 ("PCI: Fix reference leak in 
>> pci_register_host_bridge()")
>> Signed-off-by: Xiangwei Li <liwei728@huawei.com>
>> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> 

  reply	other threads:[~2025-04-12  3:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10  3:28 Xiangwei Li
2025-04-10 11:19 ` Su Hui
2025-04-12  3:18   ` liwei (JK) [this message]
2025-04-14  1:48     ` Su Hui
2025-04-14  2:41     ` liwei (JK)

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=c81b43b7-e993-4e9f-ad27-acacd0b85847@huawei.com \
    --to=liwei728@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=bobo.shaobowang@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=suhui@nfschina.com \
    --cc=wangxiongfeng2@huawei.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

all inboxes | Powered by JetHome®