From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750821AbdLZH0c (ORCPT ); Tue, 26 Dec 2017 02:26:32 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:46148 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750705AbdLZH0a (ORCPT ); Tue, 26 Dec 2017 02:26:30 -0500 X-Google-Smtp-Source: ACJfBouAEpMT4UNWaOfVkFwvvwpL3J6KzXNMn3g80JrWeuwrjqaebxweBDnOc4bdU06PJpnvPN4boQ== Date: Tue, 26 Dec 2017 12:56:26 +0530 From: gaurav jindal To: rjw@rjwysocki.net, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH]cpuidle: preventive check in cpuidle_select against crash Message-ID: <20171226072626.GA4153@gaurav.jindal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When selecting the idle state using cpuidle_select, there is no check on cpuidle_curr_governor. In cpuidle_switch_governor, cpuidle_currr_governor can be set to NULL to specify "disabled". Since cpuidle_select cannot return negative value, it has to return 0 in case of error. Printing logs and returning can help in debugging and preventing possible kernel crash scenarios. Signed-off-by: Gaurav Jindal --- diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 68a1682..bf08e3a 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -268,6 +268,19 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, */ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) { + + /* Since negative return is not allowed + * we have to return 0 even if the + * framework cannot select the idle state + */ + if (!cpuidle_curr_governor) { + pr_err("idle governor is disabled\n"); + return 0; + } + if (!cpuidle_curr_governor->select) { + pr_err("idle governor select is NULL\n"); + return 0; + } return cpuidle_curr_governor->select(drv, dev); }