linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fpga: bridge: Fix possible memory leak in fpga_bridge_register()
@ 2023-09-28  9:58 Jinjie Ruan
  0 siblings, 0 replies; only message in thread
From: Jinjie Ruan @ 2023-09-28  9:58 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_bridge_register(), the bridge
allocated by kzalloc() and the id allocated by ida_alloc() also need be
freed otherwise will cause memory leak.

Fixes: 0d70af3c2530 ("fpga: bridge: Use standard dev_release for class driver")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/fpga/fpga-bridge.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index a024be2b84e2..4a298656ce77 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -370,15 +370,15 @@ fpga_bridge_register(struct device *parent, const char *name,
 		goto error_device;
 
 	ret = device_register(&bridge->dev);
-	if (ret) {
-		put_device(&bridge->dev);
-		return ERR_PTR(ret);
-	}
+	if (ret)
+		goto error_put_device;
 
 	of_platform_populate(bridge->dev.of_node, NULL, NULL, &bridge->dev);
 
 	return bridge;
 
+error_put_device:
+	put_device(&bridge->dev);
 error_device:
 	ida_free(&fpga_bridge_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:00 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:58 [PATCH] fpga: bridge: Fix possible memory leak in fpga_bridge_register() 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).