From: gaurav jindal <gauravjindal1104@gmail.com>
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
Date: Tue, 26 Dec 2017 12:56:26 +0530 [thread overview]
Message-ID: <20171226072626.GA4153@gaurav.jindal> (raw)
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<gauravjindal1104@gmail.com>
---
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);
}
next reply other threads:[~2017-12-26 7:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-26 7:26 gaurav jindal [this message]
2017-12-27 0:42 ` [PATCH]cpuidle: preventive check in cpuidle_select against crash Rafael J. Wysocki
2017-12-27 1:57 ` gaurav jindal
2017-12-27 2:30 ` Rafael J. Wysocki
2017-12-29 18:45 ` gaurav jindal
2018-01-03 11:16 ` Rafael J. Wysocki
2018-01-04 18:09 ` gaurav jindal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171226072626.GA4153@gaurav.jindal \
--to=gauravjindal1104@gmail.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox