@@ -65,6 +65,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
cdev->ops->power2state;
}
+int thermal_cdev_set_state(struct thermal_cooling_device *cdev, int state);
void thermal_cdev_update(struct thermal_cooling_device *);
void __thermal_cdev_update(struct thermal_cooling_device *cdev);
@@ -182,14 +182,32 @@ void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
*delay_jiffies = round_jiffies(*delay_jiffies);
}
-static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
- int target)
+/**
+ * thermal_cdev_set_state - set the cooling device state
+ * @cdev: a pointer to a thermal_cooling_device
+ * @state: the target state
+ *
+ * Set the state of the cooling device passed as parameter. The
+ * cooling device lock must be held when calling this function.
+ *
+ * Return: 0 in case of success, otherwise the return value is the one
+ * returned by the backend for the ops
+ */
+int thermal_cdev_set_state(struct thermal_cooling_device *cdev, int state)
{
- if (cdev->ops->set_cur_state(cdev, target))
- return;
+ int ret;
- thermal_notify_cdev_state_update(cdev->id, target);
- thermal_cooling_device_stats_update(cdev, target);
+ /*
+ * No check is needed for the ops->set_cur_state as the
+ * registering function checked the ops are correctly set
+ */
+ ret = cdev->ops->set_cur_state(cdev, state);
+ if (!ret) {
+ thermal_notify_cdev_state_update(cdev->id, state);
+ thermal_cooling_device_stats_update(cdev, state);
+ }
+
+ return ret;
}
void __thermal_cdev_update(struct thermal_cooling_device *cdev)
@@ -207,7 +225,7 @@ void __thermal_cdev_update(struct thermal_cooling_device *cdev)
target = instance->target;
}
- thermal_cdev_set_cur_state(cdev, target);
+ thermal_cdev_set_state(cdev, target);
trace_cdev_update(cdev, target);
dev_dbg(&cdev->device, "set to state %lu\n", target);
@@ -617,12 +617,9 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
return -EINVAL;
mutex_lock(&cdev->lock);
-
- result = cdev->ops->set_cur_state(cdev, state);
- if (!result)
- thermal_cooling_device_stats_update(cdev, state);
-
+ result = thermal_cdev_set_state(cdev, state);
mutex_unlock(&cdev->lock);
+
return result ? result : count;
}
Concentrate the actions in a single place when a cooling device state is changed. Provide a function to do that instead of calling the underlying ops. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> --- drivers/thermal/thermal_core.h | 1 + drivers/thermal/thermal_helpers.c | 32 ++++++++++++++++++++++++------- drivers/thermal/thermal_sysfs.c | 7 ++----- 3 files changed, 28 insertions(+), 12 deletions(-)