From patchwork Tue May 31 06:31:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143541 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 77C0F607D6 for ; Tue, 31 May 2016 06:33:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C4F227D17 for ; Tue, 31 May 2016 06:33:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6137E27DA9; Tue, 31 May 2016 06:33:41 +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=unavailable 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 17306281C1 for ; Tue, 31 May 2016 06:33:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755827AbcEaGd3 (ORCPT ); Tue, 31 May 2016 02:33:29 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35338 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162180AbcEaGcb (ORCPT ); Tue, 31 May 2016 02:32:31 -0400 Received: by mail-pf0-f193.google.com with SMTP id f144so17859647pfa.2; Mon, 30 May 2016 23:32:31 -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=4cblRMOPlIeuHY8MWMdNTwxaFIwCfE5qUl5VnVIWI54=; b=wYkzjoqp2bu7Zwk5ZJZ1qZLq9NdZd1e9Ap4DCwqj6+xCH7pu3+RV31qi3QaeUMHThD BlB19XKRgWxH+Szqo7PNMc4JKh+tgrW2f1j0j+wQRg7FYJCB1Xq1vJj5DwwSQfQgIRFp dsjZArEfO7IQyCJQmriEzGpaVPdU14T9NtpZdpciomaY/ujvRr/aYYiY/W5uO9J8Oi7I SFo8oksmOs9V78IAQigocOoabeapG5XpEkLXvIvBHlz8bnYI0OyJp+DXMTY2K3opakwu IDp9OwAhnjNGtu0yyfa6z9n2BgbR/2H0NTWL3AWM5zqWnBVuxwRDYX+VbL1gLx2ST+RF OjIA== 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=4cblRMOPlIeuHY8MWMdNTwxaFIwCfE5qUl5VnVIWI54=; b=mpJ6qb+UAWsS97tvIaIYpu6ImSFX5+1pMONfLL3T7E1gYnoa1a1W2sV/qc0BAtFK2b 4mWNp7COxDBlGYC1vgWWz970KnYnu4i6bmMObGG4dCFt8AWe/mqVxw4SIKYxxPQuJr+w PTVdIdMz81+xV2neeGCtvc6bkqQrz7z9weDNb2OZANL5j/vVVstW0Iymg8LSa3+DxsfV uvnmNmBFF8KjreTBnX99zM5+CjvEkxSgOlQysqiJXBsebhqoAbQfhxMyKNsTILL/L0nK MNM/i4lgXdUWNMaZLSIezU7FpCZdkDX/K1FUSXLrp9sNN2x67maZIG+HiGFX7R9zw8+M UaJg== X-Gm-Message-State: ALyK8tKe4AhjQt1fkPMsrKeu6BrrfQCsjUmHvW/YXpwYejQ/PQzK4bqeHElEeH77SsZ1uA== X-Received: by 10.98.21.82 with SMTP id 79mr49576500pfv.92.1464676351266; Mon, 30 May 2016 23:32:31 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id a62sm37228945pfj.29.2016.05.30.23.32.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:32:30 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 14/15] thermal: sysfs: serialize access to instances Date: Mon, 30 May 2016 23:31:35 -0700 Message-Id: <1464676296-5610-15-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 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 Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- 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; }