UPSTREAM: PM / devfreq: Fix potential NULL pointer dereference in governor_store

df->governor is being dereferenced before it is null checked,
hence there is a potential null pointer dereference.

Notice that df->governor is being null checked at line 1004:
if (df->governor) {, which implies it might be null.

Fix this by null checking df->governor before dereferencing it.

Addresses-Coverity-ID: 1401988 ("Dereference before null check")
Fixes: bcf23c79c4 ("PM / devfreq: Fix available_governor sysfs")
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
(cherry picked from commit 63f1e05f7f)

Change-Id: I9f30f3bb6e1f6b4342c63e505d48103c752b9b28
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
This commit is contained in:
Gustavo A. R. Silva
2017-12-06 14:20:15 -06:00
committed by Tao Huang
parent b19a778913
commit fb22d5a078

View File

@@ -1000,7 +1000,8 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
if (df->governor == governor) {
ret = 0;
goto out;
} else if (df->governor->immutable || governor->immutable) {
} else if ((df->governor && df->governor->immutable) ||
governor->immutable) {
ret = -EINVAL;
goto out;
}