arm: kernel/perf_event_cpu.c: fix error null pointer dereference check
Subsystems (3)
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
@@ -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
Quoted 3 lines · Cong Ding
the pointer
cpu_pmuis 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)
Quoted 12 lines · Russell King - ARM Linux
Quoted 3 lines · Cong Ding
the pointer
cpu_pmuis 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 aftercpu_pmuhas 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
Quoted 13 lines · Cong Ding
Quoted 12 lines · Russell King - ARM Linux
Quoted 3 lines · Cong Ding
the pointer
cpu_pmuis 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 aftercpu_pmuhas 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
PATCH v2 1/1 arm: kernel/perf_event_cpu.c: remove unnecessary null pointer dereference check
In reply to Cong DingThe 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
@@ -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