Skip to contentSkip to conversation

arm: kernel/perf_event_cpu.c: fix error null pointer dereference check

PATCH Superseded Cong Ding 3 participants 5 messages Jan 14, 2013

Subsystems (3)
lore
Share & tools
lore

Cong Ding

author
#0 lore raw

PATCH 1/1 arm: kernel/perf_event_cpu.c: fix error null pointer dereference check

the pointer cpu_pmu is used without null pointer dereference check, and is checked after the using of it, so we move the null pointer check to before the first use.

---
 arch/arm/kernel/perf_event_cpu.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
arch/arm/kernel/perf_event_cpu.c +8 -6
index efa5295..16aa979 100644
@@ -142,13 +142,15 @@ static void cpu_pmu_init(struct arm_pmu *cpu_pmu)
 		raw_spin_lock_init(&events->pmu_lock);
 	}
 
-	cpu_pmu->get_hw_events	= cpu_pmu_get_cpu_events;
-	cpu_pmu->request_irq	= cpu_pmu_request_irq;
-	cpu_pmu->free_irq	= cpu_pmu_free_irq;
+	if (cpu_pmu) {
+		cpu_pmu->get_hw_events	= cpu_pmu_get_cpu_events;
+		cpu_pmu->request_irq	= cpu_pmu_request_irq;
+		cpu_pmu->free_irq	= cpu_pmu_free_irq;
 
-	/* Ensure the PMU has sane values out of reset. */
-	if (cpu_pmu && cpu_pmu->reset)
-		on_each_cpu(cpu_pmu->reset, cpu_pmu, 1);
+		/* Ensure the PMU has sane values out of reset. */
+		if (cpu_pmu->reset)
+			on_each_cpu(cpu_pmu->reset, cpu_pmu, 1);
+	}
 }
 
 /*
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 3 lines · Cong Ding

the pointer cpu_pmu is used without null pointer dereference check, and is checked after the using of it, so we move the null pointer check to before the first use.

The NULL pointer check is not necessary. cpu_pmu_init() is called after cpu_pmu has already been dereferenced by its caller:

        cpu_pmu = pmu;
        cpu_pmu->plat_device = pdev;
        cpu_pmu_init(cpu_pmu);

So...

arch/arm/kernel/perf_event_cpu.c static void cpu_pmu_init(struct arm_pmu *cpu_pmu) · line 150

Quoted 2 lines
arch/arm/kernel/perf_event_cpu.c +0 -2
-	/* Ensure the PMU has sane values out of reset. */
-	if (cpu_pmu && cpu_pmu->reset)

Just replace this with:

	if (cpu_pmu->reset)
author
#2 lore raw
Quoted 12 lines · Russell King - ARM Linux
Quoted 3 lines · Cong Ding

the pointer cpu_pmu is used without null pointer dereference check, and is checked after the using of it, so we move the null pointer check to before the first use.

The NULL pointer check is not necessary. cpu_pmu_init() is called after cpu_pmu has already been dereferenced by its caller:

        cpu_pmu = pmu;
        cpu_pmu->plat_device = pdev;
        cpu_pmu_init(cpu_pmu);
Quoted 7 lines

So...

arch/arm/kernel/perf_event_cpu.c static void cpu_pmu_init(struct arm_pmu *cpu_pmu) · line 150

Quoted 2 lines
arch/arm/kernel/perf_event_cpu.c +0 -2
-	/* Ensure the PMU has sane values out of reset. */
-	if (cpu_pmu && cpu_pmu->reset)

Just replace this with:

	if (cpu_pmu->reset)

Thanks Russell, I will send version 2.

- cong

#3 lore raw
Quoted 13 lines · Cong Ding
Quoted 12 lines · Russell King - ARM Linux
Quoted 3 lines · Cong Ding

the pointer cpu_pmu is used without null pointer dereference check, and is checked after the using of it, so we move the null pointer check to before the first use.

The NULL pointer check is not necessary. cpu_pmu_init() is called after cpu_pmu has already been dereferenced by its caller:

        cpu_pmu = pmu;
        cpu_pmu->plat_device = pdev;
        cpu_pmu_init(cpu_pmu);
Quoted 8 lines
Quoted 7 lines

So...

arch/arm/kernel/perf_event_cpu.c static void cpu_pmu_init(struct arm_pmu *cpu_pmu) · line 150

Quoted 2 lines
arch/arm/kernel/perf_event_cpu.c +0 -2
-	/* Ensure the PMU has sane values out of reset. */
-	if (cpu_pmu && cpu_pmu->reset)

Just replace this with:

	if (cpu_pmu->reset)

Thanks Russell, I will send version 2.

No need, I've taken this into my perf/updates branch.

Thanks,

Will

author
#4 lore raw

PATCH v2 1/1 arm: kernel/perf_event_cpu.c: remove unnecessary null pointer dereference check

In reply to Cong Ding

The NULL pointer check is not necessary. cpu_pmu_init() is called after cpu_pmu has already been dereferenced by its caller:

	cpu_pmu = pmu;
	cpu_pmu->plat_device = pdev;
	cpu_pmu_init(cpu_pmu);
---
 arch/arm/kernel/perf_event_cpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kernel/perf_event_cpu.c +1 -1
index efa5295..43496f6 100644
@@ -147,7 +147,7 @@ static void cpu_pmu_init(struct arm_pmu *cpu_pmu)
 	cpu_pmu->free_irq	= cpu_pmu_free_irq;
 
 	/* Ensure the PMU has sane values out of reset. */
-	if (cpu_pmu && cpu_pmu->reset)
+	if (cpu_pmu->reset)
 		on_each_cpu(cpu_pmu->reset, cpu_pmu, 1);
 }
 
Signature · 1 line
1.7.4.5