[STABLE][PATCH 4.4] thermal/core/fair share: Lock the thermal zone while looping over instances

From: Lukasz Luba
Date: Fri May 14 2021 - 06:49:38 EST


commit fef05776eb02238dcad8d5514e666a42572c3f32 upstream.

The tz->lock must be hold during the looping over the instances in that
thermal zone. This lock was missing in the governor code since the
beginning, so it's hard to point into a particular commit.

CC: stable@xxxxxxxxxxxxxxx # 4.4
Signed-off-by: Lukasz Luba <lukasz.luba@xxxxxxx>
---
Hi all,

I've backported my patch which was sent to LKML:
https://lore.kernel.org/linux-pm/20210422153624.6074-2-lukasz.luba@xxxxxxx/

The upstream patch failed while applying:
https://lore.kernel.org/stable/16206371483193@xxxxxxxxx/

This patch should apply to stable v4.4.y, on top of stable tree branch:
linux-4.4.y which head was at:
commit 47127fcd287c ("Linux 4.4.268")

Regards,
Lukasz Luba

drivers/thermal/fair_share.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/thermal/fair_share.c b/drivers/thermal/fair_share.c
index 34fe36504a55..e701356441a9 100644
--- a/drivers/thermal/fair_share.c
+++ b/drivers/thermal/fair_share.c
@@ -93,6 +93,8 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
int total_instance = 0;
int cur_trip_level = get_trip_level(tz);

+ mutex_lock(&tz->lock);
+
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
if (instance->trip != trip)
continue;
@@ -119,6 +121,8 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
instance->cdev->updated = false;
thermal_cdev_update(cdev);
}
+
+ mutex_unlock(&tz->lock);
return 0;
}

--
2.17.1