[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241219115459.GD82731@unreal>
Date: Thu, 19 Dec 2024 13:54:59 +0200
From: Leon Romanovsky <leon@...nel.org>
To: Ma Ke <make_ruc2021@....com>
Cc: bvanassche@....org, jgg@...pe.ca, linux-rdma@...r.kernel.org,
linux-kernel@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH] RDMA/srp: Fix error handling in srp_add_port
On Tue, Dec 17, 2024 at 03:55:38PM +0800, Ma Ke wrote:
> The reference count of the device incremented in device_initialize() is
> not decremented when device_add() fails. Add a put_device() call before
> returning from the function to decrement reference count for cleanup.
> Or it could cause memory leak.
>
> As comment of device_add() says, if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count.
>
> Found by code review.
>
> Cc: stable@...r.kernel.org
I slightly rewrote commit message and dropped this stable@ tag.
Thanks
> Fixes: c8e4c2397655 ("RDMA/srp: Rework the srp_add_port() error path")
> Signed-off-by: Ma Ke <make_ruc2021@....com>
> ---
> drivers/infiniband/ulp/srp/ib_srp.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
> index 2916e77f589b..7289ae0b83ac 100644
> --- a/drivers/infiniband/ulp/srp/ib_srp.c
> +++ b/drivers/infiniband/ulp/srp/ib_srp.c
> @@ -3978,7 +3978,6 @@ static struct srp_host *srp_add_port(struct srp_device *device, u32 port)
> return host;
>
> put_host:
> - device_del(&host->dev);
> put_device(&host->dev);
> return NULL;
> }
> --
> 2.25.1
>
Powered by blists - more mailing lists