From patchwork Tue May 31 06:31:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143563 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 13CCD60761 for ; Tue, 31 May 2016 06:35:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07F7327D17 for ; Tue, 31 May 2016 06:35:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0F50281C1; Tue, 31 May 2016 06:35:31 +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 9656E27D17 for ; Tue, 31 May 2016 06:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755493AbcEaGfa (ORCPT ); Tue, 31 May 2016 02:35:30 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:33213 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755525AbcEaGcP (ORCPT ); Tue, 31 May 2016 02:32:15 -0400 Received: by mail-pa0-f68.google.com with SMTP id f8so24025465pag.0; Mon, 30 May 2016 23:32:14 -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=qdHn0o93N8EwWguGavzHrQJqpQ+AlTJ1wcwXDAos38Y=; b=lP6XnRKcytSXoAJXFFhtcHLU7j3rLtMf2342Ab+qdgaq4TEG2gI06RBlJcemPULZZ+ U9wxJlhrjxa1Rlc4G+IjVV4KuzHDhCUr9iNVEkp3cqxQKAtpEPIqtBEn4YjGMX1GMPiA sFEeiOq1p2nuYxwfUeDMSuaaE14K5WEhgB4b8w05WcWm4p+cuAjLL41ZuRlwgm9kO74/ SDX5sw+ahgJmlGEoyL8ouvAXT1KaZli+lqOtM9HXn+MNUXiAusv/MnEUiynk+d4Zk2Ku beNaIHcfLgmJq4lovh51AfDvWVjvlOe9BE5wD2P4vmxSPgMWE4Ns/kGPz29Tk6kEWE9q If2A== 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=qdHn0o93N8EwWguGavzHrQJqpQ+AlTJ1wcwXDAos38Y=; b=Gw0B2uLlRQctOQb8mCk8cTFdzyj2LWlaGmL2lM4dSNd7fLBPMdf0b7MAjFdH6HmF54 bpUTpXVzbHgYlcO7WvZe7rRMyVSLgYCBzo3blRGtm9Wtql8q4Emt26hWbXh+ebtS0oO9 NgTSjg3rG/pECjs1az2/WDOZm/ZENYSrXrCMquuxpjlzGgs3Sznj5sqR0Bw9jJmg/cud vpOC21rLdXQILbCsIfrDISDbulBpLe3VECDemZQ93f+w6CYxbLkoaO9AQDw4bpeOmNA1 tj2pyfOIBAsXJQQHx2YTFMqX3/0jyZYwVr5K1GhGxo7Mdbt+8761tBCxUlU2SWmCAFM1 B7zQ== X-Gm-Message-State: ALyK8tJJ3oyOizFuq6BcqAr9VYLSpH8GjfudhULMJ86MXjkxyqjCAixqGJ2GlwmEZkFG9Q== X-Received: by 10.66.231.35 with SMTP id td3mr52499852pac.56.1464676333866; Mon, 30 May 2016 23:32:13 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id y186sm37260962pfb.13.2016.05.30.23.32.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:32:13 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 06/15] thermal: sysfs: lock tz while on passive properties Date: Mon, 30 May 2016 23:31:27 -0700 Message-Id: <1464676296-5610-7-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 Serialized calls to tz.ops in user facing sysfs handler passive_store() and passive_show(). 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index afb42a2..dcaeb17 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -252,18 +252,24 @@ passive_store(struct device *dev, struct device_attribute *attr, if (state && state < 1000) return -EINVAL; + mutex_lock(&tz->lock); if (state && !tz->forced_passive) { if (!tz->passive_delay) tz->passive_delay = 1000; + mutex_unlock(&tz->lock); thermal_zone_device_rebind_exception(tz, "Processor", sizeof("Processor")); + mutex_lock(&tz->lock); } else if (!state && tz->forced_passive) { tz->passive_delay = 0; + mutex_unlock(&tz->lock); thermal_zone_device_unbind_exception(tz, "Processor", sizeof("Processor")); + mutex_lock(&tz->lock); } tz->forced_passive = state; + mutex_unlock(&tz->lock); thermal_zone_device_update(tz); @@ -275,8 +281,13 @@ passive_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); + unsigned int passive; - return sprintf(buf, "%d\n", tz->forced_passive); + mutex_lock(&tz->lock); + passive = tz->forced_passive; + mutex_unlock(&tz->lock); + + return sprintf(buf, "%u\n", passive); } static ssize_t @@ -494,7 +505,9 @@ static umode_t thermal_zone_passive_is_visible(struct kobject *kobj, tz = container_of(dev, struct thermal_zone_device, device); for (count = 0; count < tz->trips; count++) { + mutex_lock(&tz->lock); tz->ops->get_trip_type(tz, count, &trip_type); + mutex_unlock(&tz->lock); if (trip_type == THERMAL_TRIP_PASSIVE) return attr->mode;