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>
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;
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;