* [PATCH] fpga: fpga-mgr: Fix possible memory leak in fpga_mgr_register_full()
@ 2023-09-28 9:59 Jinjie Ruan
0 siblings, 0 replies; only message in thread
From: Jinjie Ruan @ 2023-09-28 9:59 UTC (permalink / raw)
To: linux-fpga, linux-kernel, Moritz Fischer, Wu Hao, Xu Yilun,
Tom Rix, Russ Weight
Cc: ruanjinjie
If device_register() fails in fpga_mgr_register_full(), the mgr
allocated by kzalloc() and the id allocated by ida_alloc() also need be
freed otherwise will cause memory leak.
Fixes: 4ba0b2c294fe ("fpga: mgr: Use standard dev_release for class driver")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/fpga/fpga-mgr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index 06651389c592..9724f192ba16 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -827,13 +827,13 @@ fpga_mgr_register_full(struct device *parent, const struct fpga_manager_info *in
mgr->state = fpga_mgr_state(mgr);
ret = device_register(&mgr->dev);
- if (ret) {
- put_device(&mgr->dev);
- return ERR_PTR(ret);
- }
+ if (ret)
+ goto error_put_device;
return mgr;
+error_put_device:
+ put_device(&mgr->dev);
error_device:
ida_free(&fpga_mgr_ida, id);
error_kfree:
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-28 10:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-28 9:59 [PATCH] fpga: fpga-mgr: Fix possible memory leak in fpga_mgr_register_full() Jinjie Ruan
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).