Skip to contentSkip to conversation

FAILED: patch "[PATCH] PM / devfreq: Lock devfreq in trans_stat_show" failed to apply to 4.4-stable tree

PATCH [email protected] 1 participant 1 message Dec 15, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 2abb0d5268ae7b5ddf82099b1f8d5aa8414637d4 Mon Sep 17 00:00:00 2001
From: Leonard Crestez <[email protected]>
Date: Tue, 24 Sep 2019 10:52:23 +0300
Subject: [PATCH] PM / devfreq: Lock devfreq in trans_stat_show

There is no locking in this sysfs show function so stats printing can race with a devfreq_update_status called as part of freq switching or with initialization.

Also add an assert in devfreq_update_status to make it clear that lock must be held by caller.

Fixes 39688ce6facd ("PM / devfreq: account suspend/resume for stats")
drivers/devfreq/devfreq.c +9 -3
index 60859a2400bc..d6c3dce9e9d5 100644
@@ -160,6 +160,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
 	int lev, prev_lev, ret = 0;
 	unsigned long cur_time;
 
+	lockdep_assert_held(&devfreq->lock);
 	cur_time = jiffies;
 
 	/* Immediately exit if previous_freq is not initialized yet. */
@@ -1397,12 +1398,17 @@ static ssize_t trans_stat_show(struct device *dev,
 	int i, j;
 	unsigned int max_state = devfreq->profile->max_state;
 
-	if (!devfreq->stop_polling &&
-			devfreq_update_status(devfreq, devfreq->previous_freq))
-		return 0;
 	if (max_state == 0)
 		return sprintf(buf, "Not Supported.\n");
 
+	mutex_lock(&devfreq->lock);
+	if (!devfreq->stop_polling &&
+			devfreq_update_status(devfreq, devfreq->previous_freq)) {
+		mutex_unlock(&devfreq->lock);
+		return 0;
+	}
+	mutex_unlock(&devfreq->lock);
+
 	len = sprintf(buf, "     From  :   To\n");
 	len += sprintf(buf + len, "           :");
 	for (i = 0; i < max_state; i++)