linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full()
@ 2023-09-28  9:16 Jinjie Ruan
  2023-09-28 14:02 ` Xu Yilun
  2023-09-28 15:45 ` Russ Weight
  0 siblings, 2 replies; 4+ messages in thread
From: Jinjie Ruan @ 2023-09-28  9:16 UTC (permalink / raw)
  To: mdf, hao.wu, yilun.xu, trix, russell.h.weight, linux-fpga,
	linux-kernel
  Cc: ruanjinjie

If device_register() fails in fpga_region_register_full(), the region
allocated by kzalloc() and the id allocated by ida_alloc() also need be
freed otherwise will cause memory leak.

Fixes: 8886a579744f ("fpga: region: Use standard dev_release for class driver")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/fpga/fpga-region.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
index b364a929425c..9dc6314976ef 100644
--- a/drivers/fpga/fpga-region.c
+++ b/drivers/fpga/fpga-region.c
@@ -228,12 +228,13 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info *
 
 	ret = device_register(&region->dev);
 	if (ret) {
-		put_device(&region->dev);
-		return ERR_PTR(ret);
+		goto err_put_device;
 	}
 
 	return region;
 
+err_put_device:
+	put_device(&region->dev);
 err_remove:
 	ida_free(&fpga_region_ida, id);
 err_free:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-07  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-28  9:16 [PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full() Jinjie Ruan
2023-09-28 14:02 ` Xu Yilun
2023-09-28 15:45 ` Russ Weight
2023-10-07  9:15   ` Ruan Jinjie

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).