From patchwork Tue May 31 06:31:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143555 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8DB9060761 for ; Tue, 31 May 2016 06:34:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8190227D17 for ; Tue, 31 May 2016 06:34:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76832281C1; Tue, 31 May 2016 06:34:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDFC627D17 for ; Tue, 31 May 2016 06:34:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755667AbcEaGeh (ORCPT ); Tue, 31 May 2016 02:34:37 -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 Received: by mail-pf0-f193.google.com with SMTP id c84so17240395pfc.1; Mon, 30 May 2016 23:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8TPspOQ+pOYJDq4dCBt01vxoUJXwHrrshSvZs9vubNE=; b=mZh3hynEpQDhwCyLWE6sorKgSG0BT25P2t5R0ez/jaeZMBRG04HN6ycxKfj27uHN4U 7y79GJ1OgiR2grjS/v99MTe3xGEREf/x+6rpq9jTtrYPCJUVlxZKKEoLb/Lg3g+3leGg TYPtN6epJwFUL2Gu4VH21eQaFEMU7hkClISFYCK8iR6IlLZgBK1CBvy6DUjQo6yWjpxg sX/VxNNtguqD2edsqg71AT02vAY2SSgL2h8PQmUAq1S4xH0GwT5JP4Q2vfG+PHedJlJH ddF9d+1cFUHdw8cpThnapTiovPcvUoaYcptE02QWF0Sn8QMjiNj4AITPOmm4qijBeRE5 +LLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8TPspOQ+pOYJDq4dCBt01vxoUJXwHrrshSvZs9vubNE=; b=cojFK2EpIlRu5lZrWoZDIneDZuJbdO5R0f+3X1GFP5dTwBkpdBytpFVbF7uc49Io/7 w1yZx6hGaXSatcoDjo6gXLuawWklQbUgMMCIBCqYQ61fjDPrZvfMHUZfIZ8T+XNzo+GY V9QNJc5Kl3LUPfp4Ca05834avCsLh8jCSD2I9KeyeZxxyXyf1RYmU3nxItwZYag5shyx Lht6NQDMwJvdtsVmitmjZ5IUg0FMf3j23c5iUuhNJ68ZjGrafwi9ccxtkKTw2BXmmxV8 xUEwrtEOXJsB7zxzItSKVsJmtuQHjjf52uqgvwIydXp8cIt5eaR5uOk9AWdxEtAZLeBr +C+w== X-Gm-Message-State: ALyK8tKUttiaVRaMIq7WLSuROZmstnQD3emUSBubOe59sXxVyFDdjDdl/0B5fAvgrnGRJA== X-Received: by 10.98.1.132 with SMTP id 126mr52032121pfb.27.1464676343675; Mon, 30 May 2016 23:32:23 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id z12sm37262426pfj.1.2016.05.30.23.32.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:32:23 -0700 (PDT) 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }