Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2572981imu; Wed, 21 Nov 2018 13:55:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/VtfONMwzPGffd4OS9zXJAtb0TWGkGNxmKGE0sOpw2hI/ccYYI1+DgG501kJrVvhtiAINBU X-Received: by 2002:a17:902:22f:: with SMTP id 44mr6935159plc.137.1542837312467; Wed, 21 Nov 2018 13:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542837312; cv=none; d=google.com; s=arc-20160816; b=vSfPpLKP6FCMcSQbhX8JNk7y22157kqzH8vrmcJyqA2gKMgjzDBU0hKmXTGYtDItLH QpiGWqIOEyhDOalx9K22r2NGKRTxnEplC+qZjivP9sl23/IcH2YcWW4FPQuq9Q4F9sbR 364R27TqTs6qViUl7OaHtV/gYTrpmnh6e/aVvX73eLlw7XEK5Bq+YaANUYgEU0ToMZN7 fkuOHAY1/14jtQcb2yFz/hrL5fDjN+fRJ3M9VpBtnWjx+NA+H89emYzTJwT0SF9Mkll8 /lAoXboeIIEuYTZ7o8NI+bLCYEwq17eur72YVsFA1wNAZ9bTWfP6m8XI2AAUncAem6fA cwWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=/oB6qvy4AnPDvv256HxTIH+Yqrvw1FZpwg+vrRE4eHE=; b=IEalHLMtkxJGIwOTBd+Rqf7dIEsvu+IRONCIgwEaU8fpaAznwbo+e4Ho/9iGSsI0S9 kbzcLA0bPHfgufLqfpz0oc7fnpOO6tY4onsdfBdeqk+i2ONs7d7UMSPypxjfUnxslvWA SeM7qCjxilWLckkBGF26Rncbd23XovUNGsA3nlpJRXyfPRA2l3COlHdAzZYdW1oNvLOU 8POW9OIE6wP00zHYwdihCSfYwe9qT48dKVA2XGu9xzyl+R1JSb+N1Sj00XsPR5+bInS3 ifFMHWl9YWZhK5g2QnqclnDN70d7wHWTJjEJ/wLywaTT6OUFgofzZocgvMPXEnEWo82S UaFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g0PGmh6D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si38242547pgj.34.2018.11.21.13.54.57; Wed, 21 Nov 2018 13:55:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g0PGmh6D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731939AbeKVFhG (ORCPT + 99 others); Thu, 22 Nov 2018 00:37:06 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:45357 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730172AbeKVFhG (ORCPT ); Thu, 22 Nov 2018 00:37:06 -0500 Received: by mail-qt1-f193.google.com with SMTP id e5so5012123qtr.12 for ; Wed, 21 Nov 2018 11:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=/oB6qvy4AnPDvv256HxTIH+Yqrvw1FZpwg+vrRE4eHE=; b=g0PGmh6D8GTALlZdPVBg36xQfDEQ14CcNwmDJyDZsJW+3oRLtT2ePK1mEnW2DAnwrO rtbu0czijkOfKSeCYhcvmi2RVjNcDcbXP964f2sKL7GwkSN8t6NBFUrjZvmo9c0uBTH+ E44/SWrred7s7VeiQNRuo75DekyYwiO95AlXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/oB6qvy4AnPDvv256HxTIH+Yqrvw1FZpwg+vrRE4eHE=; b=MitlJScuqiJfL3Zi3/DMHSiWXBuFRmhsBsm11VABGcL2OLlcdwAb4z8EdxnMT6hL+k AvPsv4/R0jB5qdM5gulk30M523sKySci51hEKXNfdTOOsoJmvQoZ/JLgKHRLBbI59Jks P8EhHsaKc9y+FtNL4I6/dTJ3gF1KjbaiUpFuQ1kckx8WOackNBn9HUg0kuv6eKUvDwjs nbewpYwLDtRnCGsoyGouIcVfeH8cnt/eyMMTSa6HqX7XMcz0oTtsyD5EihRe/7jZFmeC nI3S4McenlTvHHwMbRQboGZobJEeE19wtymhj+o7egmlDkZmqK2i1jB9w6glXJkSp5Ju 5UMQ== X-Gm-Message-State: AA+aEWbVd6OrXKwOAHnrVuOQebEit7kthmUtvM/PuMXy4Bk2pPau3G60 IuuXvw06kC6+2MP+HS5KPj/AFg== X-Received: by 2002:a0c:d4f9:: with SMTP id y54mr7187097qvh.98.1542826893795; Wed, 21 Nov 2018 11:01:33 -0800 (PST) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.googlemail.com with ESMTPSA id l33sm19719763qta.57.2018.11.21.11.01.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Nov 2018 11:01:33 -0800 (PST) From: Thara Gopinath To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] thermal: Fix locking in cooling device sysfs update cur_state Date: Wed, 21 Nov 2018 14:01:31 -0500 Message-Id: <1542826891-28642-1-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sysfs interface to update cooling device cur_state does not currently hold cooling device lock, leading to stale values in cur_state especially if getting updated simultanelously from user space and thermal framework. Adding the proper locking code fixes this issue. Signed-off-by: Thara Gopinath --- drivers/thermal/thermal_sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 2241cea..1f0c1e2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -712,10 +712,14 @@ cur_state_store(struct device *dev, struct device_attribute *attr, if ((long)state < 0) return -EINVAL; + mutex_lock(&cdev->lock); result = cdev->ops->set_cur_state(cdev, state); - if (result) + if (result) { + mutex_unlock(&cdev->lock); return result; + } thermal_cooling_device_stats_update(cdev, state); + mutex_unlock(&cdev->lock); return count; } -- 2.1.4