Skip to contentSkip to conversation

fpga: Fix memory leak in build_info_create_dev

PATCH In review Miaoqian Lin 2 participants 2 messages May 11, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpga: Fix memory leak in build_info_create_dev

platform_device_alloc() create a platform device object. we should call platform_device_put() in error path to release the resource.

Fixes 543be3d8c999 ("fpga: add device feature list support")
---
 drivers/fpga/dfl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/fpga/dfl.c +3 -1
index 599bb21d86af..f0b945bd975f 100644
@@ -879,8 +879,10 @@ build_info_create_dev(struct build_feature_devs_info *binfo,
 	INIT_LIST_HEAD(&binfo->sub_features);
 
 	fdev->id = dfl_id_alloc(type, &fdev->dev);
-	if (fdev->id < 0)
+	if (fdev->id < 0) {
+		platform_device_put(fdev);
 		return fdev->id;
+	}
 
 	fdev->dev.parent = &binfo->cdev->region->dev;
 	fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 15 lines · Miaoqian Lin

platform_device_alloc() create a platform device object. we should call platform_device_put() in error path to release the resource.

Fixes 543be3d8c999 ("fpga: add device feature list support")
---
 drivers/fpga/dfl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/fpga/dfl.c +0 -0
index 599bb21d86af..f0b945bd975f 100644

drivers/fpga/dfl.c build_info_create_dev(struct build_feature_devs_info *binfo, · line 885

Quoted 8 lines
drivers/fpga/dfl.c +3 -1
@@ -879,8 +879,10 @@ build_info_create_dev(struct build_feature_devs_info *binfo,
 	INIT_LIST_HEAD(&binfo->sub_features);
 
 	fdev->id = dfl_id_alloc(type, &fdev->dev);
-	if (fdev->id < 0)
+	if (fdev->id < 0) {
+		platform_device_put(fdev);
 		return fdev->id;
+	}

The build_info_free() will finally put the fdev, is it?

Thanks
Yilun

Quoted 5 lines
drivers/fpga/dfl.c +0 -0
 	fdev->dev.parent = &binfo->cdev->region->dev;
 	fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
Signature · 1 line
2.25.1