Revert "thermal: Validate new state in cur_state_store()"

This reverts commit 108a6f91e2 which is
commit c408b3d1d9bbc7de5fb0304fea424ef2539da616 upstream.

It is part of a patch series applied to 5.15.91 that breaks the Android
kernel ABI.  If it is really needed, it can be brought back in an
abi-safe way in the future.

Bug: 161946584
Change-Id: Ia0d27976e69518cae500da40104c2ef095612158
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman
2023-02-02 11:42:20 +00:00
parent be0ca2fc43
commit 49a5232dfb
4 changed files with 19 additions and 14 deletions

View File

@@ -49,7 +49,11 @@ static int get_trip_level(struct thermal_zone_device *tz)
static long get_target_state(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev, int percentage, int level)
{
return (long)(percentage * level * cdev->max_state) / (100 * tz->num_trips);
unsigned long max_state;
cdev->ops->get_max_state(cdev, &max_state);
return (long)(percentage * level * max_state) / (100 * tz->num_trips);
}
/**

View File

@@ -629,7 +629,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
struct thermal_instance *pos;
struct thermal_zone_device *pos1;
struct thermal_cooling_device *pos2;
int result;
unsigned long max_state;
int result, ret;
if (trip >= tz->num_trips || trip < 0)
return -EINVAL;
@@ -646,11 +647,15 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
if (tz != pos1 || cdev != pos2)
return -EINVAL;
ret = cdev->ops->get_max_state(cdev, &max_state);
if (ret)
return ret;
/* lower default 0, upper default max_state */
lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
upper = upper == THERMAL_NO_LIMIT ? cdev->max_state : upper;
upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
if (lower > upper || upper > cdev->max_state)
if (lower > upper || upper > max_state)
return -EINVAL;
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -917,10 +922,6 @@ __thermal_cooling_device_register(struct device_node *np,
cdev->updated = false;
cdev->device.class = &thermal_class;
cdev->devdata = devdata;
if (cdev->ops->get_max_state(cdev, &cdev->max_state))
goto out_kfree_type;
thermal_cooling_device_setup_sysfs(cdev);
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
if (ret) {

View File

@@ -581,8 +581,13 @@ static ssize_t max_state_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct thermal_cooling_device *cdev = to_cooling_device(dev);
unsigned long state;
int ret;
return sprintf(buf, "%ld\n", cdev->max_state);
ret = cdev->ops->get_max_state(cdev, &state);
if (ret)
return ret;
return sprintf(buf, "%ld\n", state);
}
static ssize_t cur_state_show(struct device *dev, struct device_attribute *attr,
@@ -612,10 +617,6 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
if ((long)state < 0)
return -EINVAL;
/* Requested state should be less than max_state + 1 */
if (state > cdev->max_state)
return -EINVAL;
mutex_lock(&cdev->lock);
result = cdev->ops->set_cur_state(cdev, state);

View File

@@ -97,7 +97,6 @@ struct thermal_cooling_device_ops {
struct thermal_cooling_device {
int id;
char *type;
unsigned long max_state;
struct device device;
struct device_node *np;
void *devdata;