[PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux