Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1409879 > unrolled thread
| Started by | Eduardo Valentin <edubezval@gmail.com> |
|---|---|
| First post | 2016-05-31 08:40 +0200 |
| Last post | 2016-05-31 08:40 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 14/15] thermal: sysfs: serialize access to instances Eduardo Valentin <edubezval@gmail.com> - 2016-05-31 08:40 +0200
| From | Eduardo Valentin <edubezval@gmail.com> |
|---|---|
| Date | 2016-05-31 08:40 +0200 |
| Subject | [PATCH 14/15] thermal: sysfs: serialize access to instances |
| Message-ID | <rELvk-7hB-35@gated-at.bofh.it> |
Because instances are the result of a matching
between cdev and tz, we need to lock both
in order to access the instance reliably.
This patch locks both tz and cdev in user
facing sysfs handlers when accessing thermal
zone instance.
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
---
drivers/thermal/thermal_sysfs.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index ab78e08..31314be 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -781,14 +781,20 @@ thermal_cooling_device_trip_point_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct thermal_instance *instance;
+ int trip;
instance =
container_of(attr, struct thermal_instance, attr);
+ mutex_lock(&instance->tz->lock);
+ mutex_lock(&instance->cdev->lock);
+ trip = instance->trip;
+ mutex_unlock(&instance->cdev->lock);
+ mutex_unlock(&instance->tz->lock);
if (instance->trip == THERMAL_TRIPS_NONE)
return sprintf(buf, "-1\n");
else
- return sprintf(buf, "%d\n", instance->trip);
+ return sprintf(buf, "%d\n", trip);
}
ssize_t
@@ -796,10 +802,16 @@ thermal_cooling_device_weight_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct thermal_instance *instance;
+ int weight;
instance = container_of(attr, struct thermal_instance, weight_attr);
+ mutex_lock(&instance->tz->lock);
+ mutex_lock(&instance->cdev->lock);
+ weight = instance->weight;
+ mutex_unlock(&instance->cdev->lock);
+ mutex_unlock(&instance->tz->lock);
- return sprintf(buf, "%d\n", instance->weight);
+ return sprintf(buf, "%d\n", weight);
}
ssize_t
@@ -815,7 +827,11 @@ thermal_cooling_device_weight_store(struct device *dev,
return ret;
instance = container_of(attr, struct thermal_instance, weight_attr);
+ mutex_lock(&instance->tz->lock);
+ mutex_lock(&instance->cdev->lock);
instance->weight = weight;
+ mutex_unlock(&instance->cdev->lock);
+ mutex_unlock(&instance->tz->lock);
return count;
}
--
2.1.4
Back to top | Article view | linux.kernel
csiph-web