From 5e33579a6a9c6e7d255804b0cacad0ccb0c6a0d7 Mon Sep 17 00:00:00 2001 From: Rama Aparna Mallavarapu Date: Tue, 17 Sep 2019 16:21:39 -0700 Subject: [PATCH] devfreq: Do not allow tunable updates when device is suspended Tunables update accesses the monitor's registers for some devices. When the device is suspended, the clocks for those devices are turned off and updating the tunables of a suspended device causes the device to crash. Fix this by checking the flag dev_suspended before allowing the tunable updates. Change-Id: I3a0938edf761a9ea6d39ffeec19f35c228d5c306 Signed-off-by: Rama Aparna Mallavarapu [avajid@codeaurora.org: updated to utilize suspend_count from upstream and resolved minor merge conflicts] Signed-off-by: Amir Vajid --- drivers/devfreq/devfreq.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 56b7fcbd2ed2..631b38f57f39 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -1274,14 +1274,16 @@ static ssize_t polling_interval_store(struct device *dev, unsigned int value; int ret; - if (!df->governor) - return -EINVAL; - ret = sscanf(buf, "%u", &value); if (ret != 1) return -EINVAL; event_mutex_lock(df); + if (!df->governor || atomic_read(&df->suspend_count) > 0) { + dev_warn(dev, "device suspended, operation not allowed\n"); + event_mutex_unlock(df); + return -EINVAL; + } df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value); ret = count; event_mutex_unlock(df); @@ -1302,6 +1304,11 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, return -EINVAL; event_mutex_lock(df); + if (atomic_read(&df->suspend_count) > 0) { + dev_warn(dev, "device suspended, min freq not allowed\n"); + event_mutex_unlock(df); + return -EINVAL; + } mutex_lock(&df->lock); if (value) { @@ -1348,6 +1355,11 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, return -EINVAL; event_mutex_lock(df); + if (atomic_read(&df->suspend_count) > 0) { + event_mutex_unlock(df); + dev_warn(dev, "device suspended, max freq not allowed\n"); + return -EINVAL; + } mutex_lock(&df->lock); if (value) {