From: Schspa Shi <schspa@gmail.com>
To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com,
cw00.choi@samsung.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Schspa Shi <schspa@gmail.com>
Subject: [PATCH] PM / devfreq: Strengthen the handling of governor null pointer
Date: Fri, 1 Jul 2022 12:53:15 +0800 [thread overview]
Message-ID: <20220701045315.61456-1-schspa@gmail.com> (raw)
When new governor start failed & the old governor start failed too,
or the governor is removed, the devfreq->governor will be NULL, but
we still access it's member from devfreq->governor->name, which will
be a crash.
To fix it, change the position of Null pointer judgment before usage.
Another, If the governor is NULL, we try to assign a new governor to
it.
Signed-off-by: Schspa Shi <schspa@gmail.com>
---
drivers/devfreq/devfreq.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 01474daf4548..30d7f8c128a6 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -1270,7 +1270,13 @@ int devfreq_add_governor(struct devfreq_governor *governor)
int ret = 0;
struct device *dev = devfreq->dev.parent;
- if (!strncmp(devfreq->governor->name, governor->name,
+ /*
+ * When new governor start failed & the old governor start
+ * failed too. devfreq->governor will be NULL.
+ * Try to assign the new governor to this devfreq device.
+ */
+ if (!devfreq->governor ||
+ !strncmp(devfreq->governor->name, governor->name,
DEVFREQ_NAME_LEN)) {
/* The following should never occur */
if (devfreq->governor) {
@@ -1358,15 +1364,15 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
int ret;
struct device *dev = devfreq->dev.parent;
+ /* we should have a devfreq governor! */
+ if (!devfreq->governor) {
+ dev_warn(dev, "%s: Governor %s NOT present\n",
+ __func__, governor->name);
+ continue;
+ }
+
if (!strncmp(devfreq->governor->name, governor->name,
DEVFREQ_NAME_LEN)) {
- /* we should have a devfreq governor! */
- if (!devfreq->governor) {
- dev_warn(dev, "%s: Governor %s NOT present\n",
- __func__, governor->name);
- continue;
- /* Fall through */
- }
ret = devfreq->governor->event_handler(devfreq,
DEVFREQ_GOV_STOP, NULL);
if (ret) {
--
2.29.0
reply other threads:[~2022-07-01 4:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220701045315.61456-1-schspa@gmail.com \
--to=schspa@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
/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;
as well as URLs for NNTP newsgroup(s).