From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Thara Gopinath <thara.gopinath@linaro.org>,
Zhang Rui <rui.zhang@intel.com>, Sasha Levin <sashal@kernel.org>,
linux-pm@vger.kernel.org
Subject: [PATCH AUTOSEL 4.20 101/304] thermal: Fix locking in cooling device sysfs update cur_state
Date: Mon, 28 Jan 2019 10:40:18 -0500 [thread overview]
Message-ID: <20190128154341.47195-101-sashal@kernel.org> (raw)
In-Reply-To: <20190128154341.47195-1-sashal@kernel.org>
From: Thara Gopinath <thara.gopinath@linaro.org>
[ Upstream commit 68000a0d983f539c95ebe5dccd4f29535c7ac0af ]
Sysfs interface to update cooling device cur_state does not
currently holding cooling device lock sometimes leading to
stale values in cur_state if getting updated simultanelously
from user space and thermal framework. Adding the proper locking
code fixes this issue.
Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/thermal/thermal_sysfs.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 2241ceae7d7f..aa99edb4dff7 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -712,11 +712,14 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
if ((long)state < 0)
return -EINVAL;
+ mutex_lock(&cdev->lock);
+
result = cdev->ops->set_cur_state(cdev, state);
- if (result)
- return result;
- thermal_cooling_device_stats_update(cdev, state);
- return count;
+ if (!result)
+ thermal_cooling_device_stats_update(cdev, state);
+
+ mutex_unlock(&cdev->lock);
+ return result ? result : count;
}
static struct device_attribute
--
2.19.1
next prev parent reply other threads:[~2019-01-28 15:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190128154341.47195-1-sashal@kernel.org>
2019-01-28 15:40 ` [PATCH AUTOSEL 4.20 100/304] Thermal: do not clear passive state during system sleep Sasha Levin
2019-01-28 15:40 ` Sasha Levin [this message]
2019-01-28 15:41 ` [PATCH AUTOSEL 4.20 158/304] cpuidle: big.LITTLE: fix refcount leak Sasha Levin
2019-01-28 15:41 ` [PATCH AUTOSEL 4.20 159/304] OPP: Use opp_table->regulators to verify no regulator case Sasha Levin
2019-01-28 15:43 ` [PATCH AUTOSEL 4.20 287/304] thermal: bcm2835: enable hwmon explicitly Sasha Levin
2019-01-28 15:43 ` [PATCH AUTOSEL 4.20 289/304] thermal: tsens: qcom: do not create duplicate regmap debugfs entries Sasha Levin
2019-01-28 15:43 ` [PATCH AUTOSEL 4.20 292/304] thermal: generic-adc: Fix adc to temp interpolation Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190128154341.47195-101-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rui.zhang@intel.com \
--cc=stable@vger.kernel.org \
--cc=thara.gopinath@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).