From patchwork Mon Jan 14 17:18:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Ding X-Patchwork-Id: 1973001 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 0D74EDF2E1 for ; Mon, 14 Jan 2013 17:22:50 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tungh-0002VU-6o; Mon, 14 Jan 2013 17:19:08 +0000 Received: from mail-qa0-f45.google.com ([209.85.216.45]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tunga-0002T5-By for linux-arm-kernel@lists.infradead.org; Mon, 14 Jan 2013 17:19:01 +0000 Received: by mail-qa0-f45.google.com with SMTP id j15so1625565qaq.4 for ; Mon, 14 Jan 2013 09:18:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=tbQMzFOX9PFH8L9r0X0DbmHqdUjwWWfMvDyFF/7yv1A=; b=N6yM+073YWx4JbJZVy0JNEJzGVcxZJz6Ty3vF94dJ7DqwhHjz/whTQLbVY1y4bnCq4 /KkwGKdumw/cV/zSSUq9vJRlt613cS35tVLvzTdXEQBaBp8hPI5c+WsTXM2Nj9qr+sim HEAPOvnET6adw71n41ZYlC1fBwEBP5QddXvKp06VyrVc1f4we6CvzRqBK9pUrTY3shj8 lpBUwGq9EX6Y3nB2r0mVp8Zow5niB4urAkfFMP5A9AS3U5mcK/ENwZ42eoBIwULweT1O P046qo4PJucs2tgvjMlhD2NrlMjTeJi1SlrY3AC/eXyx/YniDM3V6TCnUoKmfspHSFmy 7YNw== X-Received: by 10.224.180.69 with SMTP id bt5mr71974038qab.36.1358183939037; Mon, 14 Jan 2013 09:18:59 -0800 (PST) Received: from localhost.localdomain (ec2-54-243-39-165.compute-1.amazonaws.com. [54.243.39.165]) by mx.google.com with ESMTPS id ou3sm9240666qeb.0.2013.01.14.09.18.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 14 Jan 2013 09:18:58 -0800 (PST) From: Cong Ding To: Will Deacon , Peter Zijlstra , Paul Mackerras , Ingo Molnar , Arnaldo Carvalho de Melo , Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm: kernel/perf_event_cpu.c: fix error null pointer dereference check Date: Mon, 14 Jan 2013 17:18:53 +0000 Message-Id: <1358183933-29160-1-git-send-email-dinggnu@gmail.com> X-Mailer: git-send-email 1.7.4.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130114_121900_700890_9332EA3C X-CRM114-Status: GOOD ( 13.51 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dinggnu[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.45 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Cong Ding X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 --- 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); + } } /*