diff options
author | Leonard Crestez <leonard.crestez@nxp.com> | 2019-09-24 10:52:23 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-12-17 20:35:03 +0100 |
commit | b1d06da38497b017739a4837b34122aa44f56d90 (patch) | |
tree | fa39a77dd26a79ca625bed8bca62594bd3b87691 | |
parent | 1fce7e81b94baf07af77e2c0a7f6736b3719897a (diff) | |
download | linux-stable-b1d06da38497b017739a4837b34122aa44f56d90.tar.gz linux-stable-b1d06da38497b017739a4837b34122aa44f56d90.tar.bz2 linux-stable-b1d06da38497b017739a4837b34122aa44f56d90.zip |
PM / devfreq: Lock devfreq in trans_stat_show
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")
Cc: stable@vger.kernel.org
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/devfreq/devfreq.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index d350253d161a..61fbaa89d7b4 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -163,6 +163,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. */ @@ -1287,12 +1288,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++) |