Re: [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv

From: Jason Gunthorpe

Date: Wed Nov 05 2025 - 08:47:01 EST


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.

Jason