Skip to contentSkip to conversation

cpufreq: imx6q: Fix the resource leak caused by incorrect error return

PATCH Superseded Jacky Bai 2 participants 2 messages May 5, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jacky Bai

author
#0 lore raw

PATCH 1/1 cpufreq: imx6q: Fix the resource leak caused by incorrect error return

Previous goto only handled the node reference, the opp table, regulator & clk resource also need to be free before error return.

---
 drivers/cpufreq/imx6q-cpufreq.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/cpufreq/imx6q-cpufreq.c +7 -8
index 3e17560b1efe..1d4ecefaabc6 100644
@@ -383,23 +383,22 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
 		goto put_reg;
 	}
 
+	/* Because we have added the OPPs here, we must free them */
+	free_opp = true;
+
 	if (of_machine_is_compatible("fsl,imx6ul") ||
 	    of_machine_is_compatible("fsl,imx6ull")) {
 		ret = imx6ul_opp_check_speed_grading(cpu_dev);
 		if (ret) {
-			if (ret == -EPROBE_DEFER)
-				goto put_node;
-
-			dev_err(cpu_dev, "failed to read ocotp: %d\n",
-				ret);
-			goto put_node;
+			if (ret != -EPROBE_DEFER)
+				dev_err(cpu_dev, "failed to read ocotp: %d\n",
+					ret);
+			goto out_free_opp;
 		}
 	} else {
 		imx6q_opp_check_speed_grading(cpu_dev);
 	}
 
-	/* Because we have added the OPPs here, we must free them */
-	free_opp = true;
 	num = dev_pm_opp_get_opp_count(cpu_dev);
 	if (num < 0) {
 		ret = num;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines

From: Jacky Bai
Sent: Sunday, May 5, 2019 12:35 PM

Previous goto only handled the node reference, the opp table, regulator & clk resource also need to be free before error return.

Better to have a 'Fixes:' tag.
Otherwise:

Regards
Dong Aisheng

Quoted 42 lines
---
 drivers/cpufreq/imx6q-cpufreq.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/cpufreq/imx6q-cpufreq.c +7 -8
index 3e17560b1efe..1d4ecefaabc6 100644
@@ -383,23 +383,22 @@ static int imx6q_cpufreq_probe(struct
 platform_device *pdev)
 		goto put_reg;
 	}
 
+	/* Because we have added the OPPs here, we must free them */
+	free_opp = true;
+
 	if (of_machine_is_compatible("fsl,imx6ul") ||
 	    of_machine_is_compatible("fsl,imx6ull")) {
 		ret = imx6ul_opp_check_speed_grading(cpu_dev);
 		if (ret) {
-			if (ret == -EPROBE_DEFER)
-				goto put_node;
-
-			dev_err(cpu_dev, "failed to read ocotp: %d\n",
-				ret);
-			goto put_node;
+			if (ret != -EPROBE_DEFER)
+				dev_err(cpu_dev, "failed to read ocotp: %d\n",
+					ret);
+			goto out_free_opp;
 		}
 	} else {
 		imx6q_opp_check_speed_grading(cpu_dev);
 	}
 
-	/* Because we have added the OPPs here, we must free them */
-	free_opp = true;
 	num = dev_pm_opp_get_opp_count(cpu_dev);
 	if (num < 0) {

ret = num;
--
2.21.0