* [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv
@ 2025-11-04 2:19 Ma Ke
2025-11-04 6:34 ` Jinpu Wang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ma Ke @ 2025-11-04 2:19 UTC (permalink / raw)
To: haris.iqbal, jinpu.wang, jgg, leon, danil.kipnis
Cc: linux-rdma, linux-kernel, akpm, Ma Ke, stable
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.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 9cb837480424 ("RDMA/rtrs: server: main functionality")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index ef4abdea3c2d..9ecc6343455d 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -1450,7 +1450,7 @@ static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
kfree(srv->chunks);
err_free_srv:
- kfree(srv);
+ put_device(&srv->dev);
return ERR_PTR(-ENOMEM);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv
2025-11-04 2:19 [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv Ma Ke
@ 2025-11-04 6:34 ` Jinpu Wang
2025-11-04 14:55 ` Markus Elfring
2025-11-05 12:57 ` Leon Romanovsky
2 siblings, 0 replies; 6+ messages in thread
From: Jinpu Wang @ 2025-11-04 6:34 UTC (permalink / raw)
To: Ma Ke
Cc: haris.iqbal, jgg, leon, danil.kipnis, linux-rdma, linux-kernel,
akpm, stable
On Tue, Nov 4, 2025 at 3:19 AM Ma Ke <make24@iscas.ac.cn> 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.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: 9cb837480424 ("RDMA/rtrs: server: main functionality")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
lgtm, thx!
Acked-by: Jack Wang <jinpu.wang@ionos.com>
> ---
> drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> index ef4abdea3c2d..9ecc6343455d 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> @@ -1450,7 +1450,7 @@ static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
> kfree(srv->chunks);
>
> err_free_srv:
> - kfree(srv);
> + put_device(&srv->dev);
> return ERR_PTR(-ENOMEM);
> }
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv
2025-11-04 2:19 [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv Ma Ke
2025-11-04 6:34 ` Jinpu Wang
@ 2025-11-04 14:55 ` Markus Elfring
2025-11-05 12:57 ` Leon Romanovsky
2 siblings, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2025-11-04 14:55 UTC (permalink / raw)
To: make24, linux-rdma
Cc: stable, LKML, Andrew Morton, Danil Kipnis, Haris Iqbal, Jack Wang,
Jason Gunthorpe, Leon Romanovsky
> get_or_create_srv() fails to call put_device() after
> device_initialize() when memory allocation fails. …
Why do you propose then to replace a kfree(srv) call by put_device(&srv->dev)?
Would an other word wrapping be a bit nicer for such a change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc4#n658
Regards,
Markus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv
2025-11-04 2:19 [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv Ma Ke
2025-11-04 6:34 ` Jinpu Wang
2025-11-04 14:55 ` Markus Elfring
@ 2025-11-05 12:57 ` Leon Romanovsky
2025-11-05 13:46 ` Jason Gunthorpe
2 siblings, 1 reply; 6+ messages in thread
From: Leon Romanovsky @ 2025-11-05 12:57 UTC (permalink / raw)
To: Ma Ke
Cc: haris.iqbal, jinpu.wang, jgg, danil.kipnis, linux-rdma,
linux-kernel, akpm, stable
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.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
There is no need in this line at all, it is not fixing anything.
Please rewrite commit message, thanks.
> Fixes: 9cb837480424 ("RDMA/rtrs: server: main functionality")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> index ef4abdea3c2d..9ecc6343455d 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> @@ -1450,7 +1450,7 @@ static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
> kfree(srv->chunks);
>
> err_free_srv:
> - kfree(srv);
> + put_device(&srv->dev);
> return ERR_PTR(-ENOMEM);
> }
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv
2025-11-05 12:57 ` Leon Romanovsky
@ 2025-11-05 13:46 ` Jason Gunthorpe
2025-11-05 14:51 ` Leon Romanovsky
0 siblings, 1 reply; 6+ messages in thread
From: Jason Gunthorpe @ 2025-11-05 13:46 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Ma Ke, haris.iqbal, jinpu.wang, danil.kipnis, linux-rdma,
linux-kernel, akpm, stable
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv
2025-11-05 13:46 ` Jason Gunthorpe
@ 2025-11-05 14:51 ` Leon Romanovsky
0 siblings, 0 replies; 6+ messages in thread
From: Leon Romanovsky @ 2025-11-05 14:51 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Ma Ke, haris.iqbal, jinpu.wang, danil.kipnis, linux-rdma,
linux-kernel, akpm, stable
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-05 14:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 2:19 [PATCH] RDMA/rtrs: server: Fix error handling in get_or_create_srv Ma Ke
2025-11-04 6:34 ` Jinpu Wang
2025-11-04 14:55 ` Markus Elfring
2025-11-05 12:57 ` Leon Romanovsky
2025-11-05 13:46 ` Jason Gunthorpe
2025-11-05 14:51 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).