diff options
author | Srikar Srimath Tirumala <srikars@nvidia.com> | 2017-09-12 12:27:13 -0700 |
---|---|---|
committer | Winnie Hsu <whsu@nvidia.com> | 2018-02-26 16:33:47 -0800 |
commit | 370b9f7a1dad9ccb7198bb0ffd30a8e7df112ab2 (patch) | |
tree | 06df6901c5a2d475830f1e9ea1daade2033bc766 | |
parent | a7e55a39cdd16f8170136f7ca18eb89bee20e885 (diff) |
thermal: add boundary check to set_cur_state
Prevent sysfs from setting a cur_state that exceeds the max cur_state
of the cooling device.
Bug 200334223
Bug 200331706
Bug 1968660
Bug 1968616
Change-Id: I935be6166a9e184683abfcdce70cb08cbe4a1350
Signed-off-by: Srikar Srimath Tirumala <srikars@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1558407
(cherry picked from commit 142cf9d96ed221124ea2b778dc37cf5db8d5702c)
Reviewed-on: https://git-master.nvidia.com/r/1661413
Reviewed-on: https://git-master.nvidia.com/r/1662626
GVS: Gerrit_Virtual_Submit
Tested-by: Amulya Yarlagadda <ayarlagadda@nvidia.com>
Reviewed-by: Winnie Hsu <whsu@nvidia.com>
-rw-r--r-- | drivers/thermal/thermal_core.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index ffb4b9c41a40..68e6e09fdb37 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -944,8 +944,8 @@ thermal_cooling_device_cur_state_store(struct device *dev, const char *buf, size_t count) { struct thermal_cooling_device *cdev = to_cooling_device(dev); - unsigned long state; - int result; + unsigned long state, max_state; + int result, ret; if (!sscanf(buf, "%ld\n", &state)) return -EINVAL; @@ -953,6 +953,13 @@ thermal_cooling_device_cur_state_store(struct device *dev, if ((long)state < 0) return -EINVAL; + ret = cdev->ops->get_max_state(cdev, &max_state); + if (ret) + return ret; + + if (state > max_state) + return -EINVAL; + result = cdev->ops->set_cur_state(cdev, state); if (result) return result; |