[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230928091636.1209914-1-ruanjinjie@huawei.com>
Date: Thu, 28 Sep 2023 17:16:36 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <mdf@...nel.org>, <hao.wu@...el.com>, <yilun.xu@...el.com>,
<trix@...hat.com>, <russell.h.weight@...el.com>,
<linux-fpga@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full()
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@...wei.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(®ion->dev);
if (ret) {
- put_device(®ion->dev);
- return ERR_PTR(ret);
+ goto err_put_device;
}
return region;
+err_put_device:
+ put_device(®ion->dev);
err_remove:
ida_free(&fpga_region_ida, id);
err_free:
--
2.34.1
Powered by blists - more mailing lists