Re: [PATCH V2] cpuidle: check dev before usage in cpuidle_use_deepest_state

From: Andy Shevchenko
Date: Thu Apr 27 2017 - 05:41:15 EST


On Thu, 2017-04-27 at 01:47 +0000, Li, Fei wrote:
> 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

FWIW:
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

P.S. V2 is mistakenly left from internal review AFAIU.

>
> Fixes: bb8313b603eb8 ("cpuidle: Allow enforcing deepest idle state
> selection")
> Signed-off-by: Li, Fei <fei.li@xxxxxxxxx>
> Tested-by: Shi, Feng <fengx.shi@xxxxxxxxx>
> ---
> Â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();
> Â}
> Â

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy