linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check
@ 2013-01-14 17:18 Cong Ding
  2013-01-14 17:23 ` Russell King - ARM Linux
  2013-01-14 17:40 ` [PATCH v2] arm: kernel/perf_event_cpu.c: remove unnecessary " Cong Ding
  0 siblings, 2 replies; 5+ messages in thread
From: Cong Ding @ 2013-01-14 17:18 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
 arch/arm/kernel/perf_event_cpu.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
index efa5295..16aa979 100644
--- a/arch/arm/kernel/perf_event_cpu.c
+++ b/arch/arm/kernel/perf_event_cpu.c
@@ -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);
+	}
 }
 
 /*
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check
  2013-01-14 17:18 [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check Cong Ding
@ 2013-01-14 17:23 ` Russell King - ARM Linux
  2013-01-14 17:38   ` Cong Ding
  2013-01-14 17:40 ` [PATCH v2] arm: kernel/perf_event_cpu.c: remove unnecessary " Cong Ding
  1 sibling, 1 reply; 5+ messages in thread
From: Russell King - ARM Linux @ 2013-01-14 17:23 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jan 14, 2013 at 05:18:53PM +0000, Cong Ding wrote:
> 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...

> -	/* Ensure the PMU has sane values out of reset. */
> -	if (cpu_pmu && cpu_pmu->reset)

Just replace this with:
	if (cpu_pmu->reset)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check
  2013-01-14 17:23 ` Russell King - ARM Linux
@ 2013-01-14 17:38   ` Cong Ding
  2013-01-14 17:40     ` Will Deacon
  0 siblings, 1 reply; 5+ messages in thread
From: Cong Ding @ 2013-01-14 17:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jan 14, 2013 at 05:23:46PM +0000, Russell King - ARM Linux wrote:
> On Mon, Jan 14, 2013 at 05:18:53PM +0000, Cong Ding wrote:
> > 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...
> 
> > -	/* 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check
  2013-01-14 17:38   ` Cong Ding
@ 2013-01-14 17:40     ` Will Deacon
  0 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2013-01-14 17:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jan 14, 2013 at 05:38:26PM +0000, Cong Ding wrote:
> On Mon, Jan 14, 2013 at 05:23:46PM +0000, Russell King - ARM Linux wrote:
> > On Mon, Jan 14, 2013 at 05:18:53PM +0000, Cong Ding wrote:
> > > 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...
> > 
> > > -	/* 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] arm: kernel/perf_event_cpu.c: remove unnecessary null pointer dereference check
  2013-01-14 17:18 [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check Cong Ding
  2013-01-14 17:23 ` Russell King - ARM Linux
@ 2013-01-14 17:40 ` Cong Ding
  1 sibling, 0 replies; 5+ messages in thread
From: Cong Ding @ 2013-01-14 17:40 UTC (permalink / raw)
  To: linux-arm-kernel

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);

Signed-off-by: Cong Ding <dinggnu@gmail.com>
---
 arch/arm/kernel/perf_event_cpu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
index efa5295..43496f6 100644
--- a/arch/arm/kernel/perf_event_cpu.c
+++ b/arch/arm/kernel/perf_event_cpu.c
@@ -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);
 }
 
-- 
1.7.4.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-14 17:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-14 17:18 [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check Cong Ding
2013-01-14 17:23 ` Russell King - ARM Linux
2013-01-14 17:38   ` Cong Ding
2013-01-14 17:40     ` Will Deacon
2013-01-14 17:40 ` [PATCH v2] arm: kernel/perf_event_cpu.c: remove unnecessary " Cong Ding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).