On Wed, Nov 05, 2025 at 09:46:59AM -0400, Jason Gunthorpe wrote:
On Wed, Nov 05, 2025 at 02:57:13PM +0200, Leon Romanovsky wrote:
On Tue, Nov 04, 2025 at 10:19:00AM +0800, Ma Ke wrote:
get_or_create_srv() fails to call put_device() after device_initialize() when memory allocation fails. This could cause reference count leaks during error handling, preventing proper device cleanup and resulting in memory leaks.
Nothing from above is true. put_device is preferable way to release memory after call to device_initialize(), but direct call to kfree is also fine.
Once device_initialize() happens you must call put_device(), it is one of Greg's rules.
According to the documentation it is not must, but is very good to have.
This sentence from above commit message is wrong: "This could cause reference count leaks during error handling, preventing proper device cleanup and resulting in memory leaks."
It won't cause to reference count leaks and doesn't have memory leaks in this flow.
Thanks
Jason