]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM / devfreq: Check governor before using governor->name
authorLifeng Zheng <zhenglifeng1@huawei.com>
Mon, 21 Apr 2025 03:00:20 +0000 (11:00 +0800)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 14 Jul 2025 11:04:17 +0000 (20:04 +0900)
Commit 96ffcdf239de ("PM / devfreq: Remove redundant governor_name from
struct devfreq") removes governor_name and uses governor->name to replace
it. But devfreq->governor may be NULL and directly using
devfreq->governor->name may cause null pointer exception. Move the check of
governor to before using governor->name.

Fixes: 96ffcdf239de ("PM / devfreq: Remove redundant governor_name from struct devfreq")
Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
Link: https://lore.kernel.org/lkml/20250421030020.3108405-5-zhenglifeng1@huawei.com/
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
drivers/devfreq/devfreq.c

index 18e3f7e063a4bff49f21c1a71af99ec486aa82d0..46f3a8053197b8ea054323a5fa76fe185684d856 100644 (file)
@@ -1376,15 +1376,11 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
                int ret;
                struct device *dev = devfreq->dev.parent;
 
+               if (!devfreq->governor)
+                       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) {