Skip to contentSkip to conversation

drivers: firmware: xilinx: Fix dereferencing freed memory

PATCH Applied Rajan Vaja 2 participants 2 messages Feb 8, 2021 – Feb 12, 2021 Arm/Zynq architecture

lore
Share & tools
lore

Rajan Vaja

author
#0 lore raw

PATCH 1/1 drivers: firmware: xilinx: Fix dereferencing freed memory

From: Tejas Patel <[email protected]>

Fix smatch warning:
drivers/firmware/xilinx/zynqmp.c:1288 zynqmp_firmware_remove()
error: dereferencing freed memory 'feature_data'

Use hash_for_each_safe for safe removal of hash entry.

Fixes acfdd18591ea ("firmware: xilinx: Use hash-table for api feature check")
---
 drivers/firmware/xilinx/zynqmp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +3 -2
index 7eb9958..83082e2 100644
@@ -2,7 +2,7 @@
 /*
  * Xilinx Zynq MPSoC Firmware layer
  *
- *  Copyright (C) 2014-2020 Xilinx, Inc.
+ *  Copyright (C) 2014-2021 Xilinx, Inc.
  *
  *  Michal Simek <[email protected]>
  *  Davorin Mista <[email protected]>
@@ -1280,12 +1280,13 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)
 static int zynqmp_firmware_remove(struct platform_device *pdev)
 {
 	struct pm_api_feature_data *feature_data;
+	struct hlist_node *tmp;
 	int i;
 
 	mfd_remove_devices(&pdev->dev);
 	zynqmp_pm_api_debugfs_exit();
 
-	hash_for_each(pm_api_features_map, i, feature_data, hentry) {
+	hash_for_each_safe(pm_api_features_map, i, tmp, feature_data, hentry) {
 		hash_del(&feature_data->hentry);
 		kfree(feature_data);
 	}
Signature · 7 lines
2.7.4


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Applied
#1 lore raw
Quoted 36 lines · Rajan Vaja

From: Tejas Patel <[email protected]>

Fix smatch warning:
drivers/firmware/xilinx/zynqmp.c:1288 zynqmp_firmware_remove()
error: dereferencing freed memory 'feature_data'

Use hash_for_each_safe for safe removal of hash entry.

Fixes acfdd18591ea ("firmware: xilinx: Use hash-table for api feature check")
---
 drivers/firmware/xilinx/zynqmp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +2 -1
index 7eb9958..83082e2 100644
@@ -2,7 +2,7 @@
 /*
  * Xilinx Zynq MPSoC Firmware layer
  *
- *  Copyright (C) 2014-2020 Xilinx, Inc.
+ *  Copyright (C) 2014-2021 Xilinx, Inc.
  *
  *  Michal Simek <[email protected]>
  *  Davorin Mista <[email protected]>
@@ -1280,12 +1280,13 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)
 static int zynqmp_firmware_remove(struct platform_device *pdev)
 {
 	struct pm_api_feature_data *feature_data;
+	struct hlist_node *tmp;

drivers/firmware/xilinx/zynqmp.c static int zynqmp_firmware_probe(struct platform_device *pdev) · line 1292

Quoted 10 lines
drivers/firmware/xilinx/zynqmp.c +1 -1
 	int i;
 
 	mfd_remove_devices(&pdev->dev);
 	zynqmp_pm_api_debugfs_exit();
 
-	hash_for_each(pm_api_features_map, i, feature_data, hentry) {
+	hash_for_each_safe(pm_api_features_map, i, tmp, feature_data, hentry) {
 		hash_del(&feature_data->hentry);
 		kfree(feature_data);
 	}

Applied.

Thanks,
Michal