]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/commitdiff
thermal: add boundary check to set_cur_state
authorSrikar Srimath Tirumala <srikars@nvidia.com>
Tue, 12 Sep 2017 19:27:13 +0000 (12:27 -0700)
committerWinnie Hsu <whsu@nvidia.com>
Wed, 7 Feb 2018 17:35:03 +0000 (09:35 -0800)
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
Bug 1968653

Change-Id: I935be6166a9e184683abfcdce70cb08cbe4a1350
Reviewed-on: https://git-master.nvidia.com/r/1630002
Reviewed-by: Jeetesh Burman <jburman@nvidia.com>
Tested-by: Jeetesh Burman <jburman@nvidia.com>
Reviewed-by: Bibek Basu <bbasu@nvidia.com>
Signed-off-by: Prabhu Kuttiyam <pkuttiyam@nvidia.com>
Signed-off-by: Srikar Srimath Tirumala <srikars@nvidia.com>
(cherry picked from commit 66c223caacc3dfc7110f04ffbde36b68d6941244)
Reviewed-on: https://git-master.nvidia.com/r/1652919
GVS: Gerrit_Virtual_Submit
Tested-by: Bibek Basu <bbasu@nvidia.com>
drivers/thermal/thermal_core.c

index 12b99bc4359a9ef91c26cf85f17415830d382b41..1167316081c06306599d50c2a3906a30d1d2749e 100644 (file)
@@ -1270,8 +1270,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;
@@ -1279,6 +1279,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;