Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754862AbdD0Brn convert rfc822-to-8bit (ORCPT ); Wed, 26 Apr 2017 21:47:43 -0400 Received: from mga14.intel.com ([192.55.52.115]:9971 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751654AbdD0Brf (ORCPT ); Wed, 26 Apr 2017 21:47:35 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,256,1488873600"; d="scan'208";a="92660478" From: "Li, Fei" To: "Shi, FengX" , "rjw@rjwysocki.net" , "daniel.lezcano@linaro.org" CC: "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Koul, Vinod" , "Shevchenko, Andriy" Subject: [PATCH V2] cpuidle: check dev before usage in cpuidle_use_deepest_state Thread-Topic: [PATCH V2] cpuidle: check dev before usage in cpuidle_use_deepest_state Thread-Index: AdK+9+yzWshmbIUNTv6lIceBp0YVJA== Date: Thu, 27 Apr 2017 01:47:25 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1264 Lines: 42 In case of there is no cpuidle devices registered, dev will be null, and panic will be triggered like below; In this patch, add checking of dev before usage, like that done in cpuidle_idle_call. Panic without fix: [ 184.961328] BUG: unable to handle kernel NULL pointer dereference at (null) [ 184.961328] IP: cpuidle_use_deepest_state+0x30/0x60 ... [ 184.961328] play_idle+0x8d/0x210 [ 184.961328] ? __schedule+0x359/0x8e0 [ 184.961328] ? _raw_spin_unlock_irqrestore+0x28/0x50 [ 184.961328] ? kthread_queue_delayed_work+0x41/0x80 [ 184.961328] clamp_idle_injection_func+0x64/0x1e0 Fixes: bb8313b603eb8 ("cpuidle: Allow enforcing deepest idle state selection") Signed-off-by: Li, Fei Tested-by: Shi, Feng --- drivers/cpuidle/cpuidle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 548b90b..2706be7 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -111,7 +111,8 @@ void cpuidle_use_deepest_state(bool enable) preempt_disable(); dev = cpuidle_get_device(); - dev->use_deepest_state = enable; + if (dev) + dev->use_deepest_state = enable; preempt_enable(); } -- 1.9.1 Best Regards, Fei