3.16.82-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Leonard Crestez leonard.crestez@nxp.com
commit 2abb0d5268ae7b5ddf82099b1f8d5aa8414637d4 upstream.
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") Signed-off-by: Leonard Crestez leonard.crestez@nxp.com Reviewed-by: Matthias Kaehlcke mka@chromium.org Reviewed-by: Chanwoo Choi cw00.choi@samsung.com Signed-off-by: Chanwoo Choi cw00.choi@samsung.com [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings ben@decadent.org.uk --- --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -95,6 +95,7 @@ static int devfreq_update_status(struct int lev, prev_lev, ret = 0; unsigned long cur_time;
+ lockdep_assert_held(&devfreq->lock); cur_time = jiffies;
prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq); @@ -1054,9 +1055,13 @@ static ssize_t trans_stat_show(struct de int i, j; unsigned int max_state = devfreq->profile->max_state;
+ mutex_lock(&devfreq->lock); if (!devfreq->stop_polling && - devfreq_update_status(devfreq, devfreq->previous_freq)) + 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, " :");