Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5069a29e authored by Manaf Meethalavalappu Pallikunhi's avatar Manaf Meethalavalappu Pallikunhi
Browse files

drivers: thermal: validate cdev sysfs cur_state request before using it



There is a chance that userspace cooling device cur_state sysfs node
can request any random value. It may be a value greater than
max supported state. In that case if cooling device is not
bailing out, cooling device stats module may behave unexpectedly.

Validate whether cur_state request is within the range of max
supported state or not for each cooling device. If it is greater than
max_state, bail out for that request for different cooling devices.

Change-Id: Iaa6216ad1d2f1e5b92469cd3904715dd6c0b940c
Signed-off-by: default avatarManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
parent 07c19948
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -850,6 +850,9 @@ static int cdsp_get_cur_state(struct thermal_cooling_device *cdev,
static int cdsp_set_cur_state(struct thermal_cooling_device *cdev,
				unsigned long state)
{
	if (state > CDSP_THERMAL_MAX_STATE)
		return -EINVAL;

	if (gcdsprm.thermal_cdsp_level == state)
		return 0;

@@ -883,6 +886,9 @@ static int hvx_get_cur_state(struct thermal_cooling_device *cdev,
static int hvx_set_cur_state(struct thermal_cooling_device *cdev,
				unsigned long state)
{
	if (state > HVX_THERMAL_MAX_STATE)
		return -EINVAL;

	if (gcdsprm.thermal_hvx_level == state)
		return 0;

+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ static int cpu_isolate_set_cur_state(struct thermal_cooling_device *cdev,

	/* Request state should be less than max_level */
	if (state > CPU_ISOLATE_LEVEL)
		state = CPU_ISOLATE_LEVEL;
		return -EINVAL;

	state = !!state;
	/* Check if the old cooling action is same as new cooling action */
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ static int cxip_lm_set_cur_state(struct thermal_cooling_device *cdev,
	int ret = 0;

	if (state > CXIP_LM_CDEV_MAX_STATE)
		state = CXIP_LM_CDEV_MAX_STATE;
		return -EINVAL;

	if (cxip_dev->state == state)
		return 0;
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ static int lmh_cpu_vdd_set_cur_state(struct thermal_cooling_device *cdev,
	struct lmh_cpu_vdd_cdev *vdd_cdev = cdev->devdata;

	if (state > LMH_CPU_VDD_MAX_LVL)
		state = LMH_CPU_VDD_MAX_LVL;
		return -EINVAL;

	state = !!state;
	/* Check if the old cooling action is same as new cooling action */
+2 −2
Original line number Diff line number Diff line
@@ -266,7 +266,7 @@ static int qmi_set_cur_state(struct thermal_cooling_device *cdev,
		return 0;

	if (state > qmi_cdev->max_level)
		state = qmi_cdev->max_level;
		return -EINVAL;

	return qmi_set_cur_or_min_state(qmi_cdev, state);
}
@@ -283,7 +283,7 @@ static int qmi_set_min_state(struct thermal_cooling_device *cdev,
		return 0;

	if (state > qmi_cdev->max_level)
		state = qmi_cdev->max_level;
		return -EINVAL;

	/* Convert state into QMI client expects for min state */
	state = qmi_cdev->max_level - state;
Loading