From patchwork Wed Nov 21 19:01:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 151705 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2314800ljp; Wed, 21 Nov 2018 11:01:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/ULrvx6Msa6fxVoNc7VAacy9CnjtUHFj8q5+n7uNVVx6tvUwdtQENuSdCNZJzF94ZhKkBdg X-Received: by 2002:a17:902:6b4a:: with SMTP id g10-v6mr7689267plt.19.1542826896761; Wed, 21 Nov 2018 11:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542826896; cv=none; d=google.com; s=arc-20160816; b=lm1uHF7IUpFoSy1AvNyCLmYBW+Oxxaq+ox6YFifsXhS4wVD/B7yzn4tsh6YthN6Jtp vRaKIkcc1461n4zT0FvacUNrlNtxPyTjyh2ndUOWDr3yO0+UC1YWFEA4uk0K3TGYdsvh clSpbAgwOUXywsaGEceVywe5UrAhiTArNxI6w8a6VulGptJZhzAUaLtIBzJ+Fi4zNRvK JY6z7U5HTCC5Filr+g9e3qYeDcEuNbrlFSlRZFo6jrdqUWkpSogl3djixRYHhI3FnFHd 1gNPpTrnMEJh1I7tU7ai6qqTb3rB2Yhl6bnD+HoCm+CJX9df6ELjFuy5DMorX5R2KSJk mSKg== 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 a193si31842812pfa.214.2018.11.21.11.01.36; Wed, 21 Nov 2018 11:01:36 -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 S1731949AbeKVFhG (ORCPT + 32 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(-) -- 2.1.4 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; }