From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756091AbcEaGej (ORCPT ); Tue, 31 May 2016 02:34:39 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34594 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162078AbcEaGcY (ORCPT ); Tue, 31 May 2016 02:32:24 -0400 From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 09/15] thermal: sysfs: lock tz when access sustainable power properties Date: Mon, 30 May 2016 23:31:30 -0700 Message-Id: <1464676296-5610-10-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464676296-5610-1-git-send-email-edubezval@gmail.com> References: <1464676296-5610-1-git-send-email-edubezval@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Lock tz when in user facing sysfs handlers to expose sustainable power properties. This includes: sustainable_power_show() sustainable_power_store() Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_sysfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 32ffadf..5b08d64 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -360,9 +360,14 @@ sustainable_power_show(struct device *dev, struct device_attribute *devattr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); + unsigned int sustainable_power; + + mutex_lock(&tz->lock); + sustainable_power = tz->tzp->sustainable_power; + mutex_unlock(&tz->lock); if (tz->tzp) - return sprintf(buf, "%u\n", tz->tzp->sustainable_power); + return sprintf(buf, "%u\n", sustainable_power); else return -EIO; } @@ -380,7 +385,9 @@ sustainable_power_store(struct device *dev, struct device_attribute *devattr, if (kstrtou32(buf, 10, &sustainable_power)) return -EINVAL; + mutex_lock(&tz->lock); tz->tzp->sustainable_power = sustainable_power; + mutex_unlock(&tz->lock); return count; } -- 2.1.4