Skip to contentSkip to conversation

arm64: perf: Don't use of_node after putting it

PATCH In review Stephen Boyd 2 participants 4 messages Jun 3, 2015 – Jun 5, 2015

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

PATCH 1/2 arm64: perf: Don't use of_node after putting it

It's possible, albeit unlikely, that using the of_node here will reference freed memory. Call of_node_put() after printing the name to be safe.

---
 arch/arm64/kernel/perf_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/perf_event.c +2 -1
index 702591f6180a..8af7784a8e35 100644
@@ -1340,12 +1340,13 @@ static int armpmu_device_probe(struct platform_device *pdev)
 			if (arch_find_n_match_cpu_physical_id(dn, cpu, NULL))
 				break;
 
-		of_node_put(dn);
 		if (cpu >= nr_cpu_ids) {
 			pr_warn("Failed to find logical CPU for %s\n",
 				dn->name);
+			of_node_put(dn);
 			break;
 		}
+		of_node_put(dn);
 
 		irqs[i] = cpu;
 	}
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH 2/2 arm: perf: Don't use of_node after putting it

It's possible, albeit unlikely, that using the of_node here will reference freed memory. Call of_node_put() after printing the name to be safe.

---
 arch/arm/kernel/perf_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/kernel/perf_event.c +2 -1
index 357f57ea83f4..54272e0be713 100644
@@ -818,12 +818,13 @@ static int of_pmu_irq_cfg(struct arm_pmu *pmu)
 			if (arch_find_n_match_cpu_physical_id(dn, cpu, NULL))
 				break;
 
-		of_node_put(dn);
 		if (cpu >= nr_cpu_ids) {
 			pr_warn("Failed to find logical CPU for %s\n",
 				dn->name);
+			of_node_put(dn);
 			break;
 		}
+		of_node_put(dn);
 
 		irqs[i] = cpu;
 		cpumask_set_cpu(cpu, &pmu->supported_cpus);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
In reply to Stephen Boyd

Hi Stephen,

Quoted 18 lines · Stephen Boyd

It's possible, albeit unlikely, that using the of_node here will reference freed memory. Call of_node_put() after printing the name to be safe.

---
 arch/arm64/kernel/perf_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/perf_event.c +0 -1
index 702591f6180a..8af7784a8e35 100644
@@ -1340,12 +1340,13 @@ static int armpmu_device_probe(struct platform_device *pdev)
 			if (arch_find_n_match_cpu_physical_id(dn, cpu, NULL))
 				break;
 
-		of_node_put(dn);

arch/arm64/kernel/perf_event.c static int armpmu_device_probe(struct platform_device *pdev) · line 1352

Quoted 10 lines
arch/arm64/kernel/perf_event.c +2 -0
 		if (cpu >= nr_cpu_ids) {
 			pr_warn("Failed to find logical CPU for %s\n",
 				dn->name);
+			of_node_put(dn);
 			break;
 		}
+		of_node_put(dn);
 
 		irqs[i] = cpu;
 	}

Yeah, I agree this needs changing but given (a) the CPU node isn't going to disappear and (b) this patch will conflict horribly with my queue for 4.2, do you mind if I sit on this until after the merge window (as a fix for 4.2)?

Will

#3 lore raw
Quoted 21 lines · Will Deacon
Quoted 20 lines · Stephen Boyd
  arch/arm64/kernel/perf_event.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/perf_event.c +2 -1
index 702591f6180a..8af7784a8e35 100644
@@ -1340,12 +1340,13 @@ static int armpmu_device_probe(struct platform_device *pdev)
  			if (arch_find_n_match_cpu_physical_id(dn, cpu, NULL))
  				break;
 
-		of_node_put(dn);
  		if (cpu >= nr_cpu_ids) {
  			pr_warn("Failed to find logical CPU for %s\n",
  				dn->name);
+			of_node_put(dn);
  			break;
  		}
+		of_node_put(dn);
 
Quoted 8 lines

arch/arm64/kernel/perf_event.c static int armpmu_device_probe(struct platform_device *pdev) · line 1352

Quoted 2 lines
arch/arm64/kernel/perf_event.c +0 -0
  		irqs[i] = cpu;
  	}

Yeah, I agree this needs changing but given (a) the CPU node isn't going to disappear and (b) this patch will conflict horribly with my queue for 4.2, do you mind if I sit on this until after the merge window (as a fix for 4.2)?

Sure, no problem.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project