From patchwork Tue Aug 14 11:52:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jon Medhurst (Tixy)" X-Patchwork-Id: 1319091 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 2DB15E010A for ; Tue, 14 Aug 2012 11:55:49 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T1Ffy-0001yy-TN; Tue, 14 Aug 2012 11:52:46 +0000 Received: from smarthost04.mail.zen.net.uk ([212.23.1.4]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T1Ffv-0001yk-Ra for linux-arm-kernel@lists.infradead.org; Tue, 14 Aug 2012 11:52:44 +0000 Received: from [82.69.122.217] (helo=[192.168.2.110]) by smarthost04.mail.zen.net.uk with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1T1Ffj-0005Ml-V1; Tue, 14 Aug 2012 11:52:32 +0000 Message-ID: <1344945151.2674.56.camel@linaro1.home> Subject: [PATCH] cpuidle: Prevent null pointer dereference in cpuidle_coupled_cpu_notify From: "Jon Medhurst (Tixy)" To: linux-kernel@vger.kernel.org Date: Tue, 14 Aug 2012 12:52:31 +0100 X-Mailer: Evolution 3.4.3-1 Mime-Version: 1.0 X-Originating-Smarthost04-IP: [82.69.122.217] X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [212.23.1.4 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: "Rafael J. Wysocki" , Len Brown , linux-pm@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, Colin Cross 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: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When a kernel is built to support multiple hardware types it's possible that CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED is set but the hardware the kernel is run on doesn't support cpuidle and therefore doesn't load a driver for it. In this case, when the system is shut down, cpuidle_coupled_cpu_notify() gets called with cpuidle_devices set to NULL. There are quite possibly other circumstances where this situation can also occur and we should check for it. Signed-off-by: Jon Medhurst --- Would a better fix be to delay registering the notifier until cpuidle_coupled_register_device() is called? Though following through with that logic would require unregistering the notifier when cpuidle driver is unregistered and it still seems possible that there would still be a window of opportunity for things to go wrong. drivers/cpuidle/coupled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpuidle/coupled.c b/drivers/cpuidle/coupled.c index 2c9bf26..c78a5ff 100644 --- a/drivers/cpuidle/coupled.c +++ b/drivers/cpuidle/coupled.c @@ -681,7 +681,7 @@ static int cpuidle_coupled_cpu_notify(struct notifier_block *nb, mutex_lock(&cpuidle_lock); dev = per_cpu(cpuidle_devices, cpu); - if (!dev->coupled) + if (!dev || !dev->coupled) goto out; switch (action & ~CPU_TASKS_FROZEN) {