lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20230928095818.1297547-1-ruanjinjie@huawei.com>
Date:   Thu, 28 Sep 2023 17:58:18 +0800
From:   Jinjie Ruan <ruanjinjie@...wei.com>
To:     <linux-fpga@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        Moritz Fischer <mdf@...nel.org>, Wu Hao <hao.wu@...el.com>,
        Xu Yilun <yilun.xu@...el.com>, Tom Rix <trix@...hat.com>,
        Russ Weight <russell.h.weight@...el.com>
CC:     <ruanjinjie@...wei.com>
Subject: [PATCH] fpga: bridge: Fix possible memory leak in fpga_bridge_register()

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@...wei.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ