在 2025/4/10 19:19, Su Hui 写道:1020 dev_set_name(&bus->dev, "%04x:%02x", pci_domain_nr(bus), bus->number);
On 2025/4/10 11:28, Xiangwei Li wrote:Sorry, I missed the initialization of refcount in device_initialize,
This reverts commit 804443c1f27883926de94c849d91f5b7d7d696e9.I think you missed some thing about device_register(). This patch is wrong.
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,
device_register()
-> device_initialize()
-> kobject_init()
-> kobject_init_internal()
-> kref_init(&kobj->kref); //set kref->refcount to 1
^^^^^^^^^^^^^^^^^^^^^
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?