From patchwork Tue Nov 27 22:43:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 152172 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp362205ljp; Tue, 27 Nov 2018 14:43:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/UMvl08NyMTWNUGwwyauUgUFAqkYUDGTTiNIZUSP3WJFT+nbrn7b61auiS0dr2Uogfj/BgD X-Received: by 2002:a17:902:1105:: with SMTP id d5mr23560524pla.47.1543358595999; Tue, 27 Nov 2018 14:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543358595; cv=none; d=google.com; s=arc-20160816; b=P1tw58n8x0ibaHWgXnx7p05JD8cBIpVyXh4Z2XdyTk53aVMs9vaiWDJOZCKXgR7Feb bPgsCFx1hLr9aO46pupuo+wXJYtxJD4EzTRTII75x+ojUf4mrgnKFESzS6vsBHcpcaWF KvlhBS4BvAo0qSgqa7PcIIngeoD2dcGZUiqMDF+n19j7bxHtRzTFfTbrI92Qvb3JPRjH I07GavlzwnlTnbSCo3wQF0XMT6Qtm2IEoH9Ls7iu45gH50s3qYmjsC5wGES28Xo44ipc W9WkGkYaafB/4f7JW1TqrbhL8txi0uczOtmWJpW0glHmtp/VZPwb/5QwYseREs7NpJJV GrHg== 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=Cq3ZiD+tGx4j1Y3n8GtCqDnN/1DyE4U5i4dIPs02Xnw=; b=lNaPaq1gJ4Bly5JYDcYu0I0sE+D/dAJ5Ep/SiRxfssfeHs/CyD18V18xnitBO/XDSv JrEyz4sEvON513VdfCyEcQdrg0SUhceXIarpgtd5e4pUo6634TxgxSnoSwn2H69y6G+x PZrXB/4IwH20THqGOSBAJ/F4kjSIRa/PHmyXA9OOIfjrI1jqUF4kTIuYNva3hxUMZkxS sortEWPQoj1sKSKwaunKJvpeeQAcng1XgkYL4Y1srARgzADQWmduqnCzlYmu47uxbsg0 jQv5MgDY44WN84Bk2JmVLHJWQvZMuzIpxRADVhHCkiq45smbzOryXZf5BQjPPncNSUgY G3Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YqKBgcXu; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 f18si1575252pgl.457.2018.11.27.14.43.15; Tue, 27 Nov 2018 14:43:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=YqKBgcXu; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1727010AbeK1Jmi (ORCPT + 11 others); Wed, 28 Nov 2018 04:42:38 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:44567 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726772AbeK1Jmi (ORCPT ); Wed, 28 Nov 2018 04:42:38 -0500 Received: by mail-qk1-f194.google.com with SMTP id n12so15643296qkh.11 for ; Tue, 27 Nov 2018 14:43:14 -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=Cq3ZiD+tGx4j1Y3n8GtCqDnN/1DyE4U5i4dIPs02Xnw=; b=YqKBgcXuzfqf6mvM/JRx1ZUyRRCtXurID5eUHr6bo74c5ugs2KjfjCiYirZgjMVssA or4TQjBGtQ4LcTlagZXkWWFgIQ28Bjs/PZw25QyGEAuRQobyjmEx8AcWC62VJcFwwovA T7zn7vDE2YhhRrDCYz77COdyyeZjXfbiYszC8= 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=Cq3ZiD+tGx4j1Y3n8GtCqDnN/1DyE4U5i4dIPs02Xnw=; b=RJdbRuj7sfRrPvsTaJ/l/bJ8AkVA6gewhllZHQfu5AEiwIIAakdSrA5j7eO7Ps/7TB ONb93rJFU6eMJBU56ciII0blD9zBMsit/A3m0uo7soNBt7Nh/fBS41CmUq+Kj01FuJUj S1gYLCD6E8or9lAO632yH3ltjEr9FL2MBZ4u3HkhrNq9922yUlSyIQjdrbf4G0iSjGVE 2cSMpJboJodAYxPbcc8UY+DULpdLzJeb7VktRaGjHHGz1j9wVJBGfLiXnJBYhCvaBQNi gr2rLRf2DejBgSaWJ/VNusIvFPrBtEhQsPMyBjAtEWAIxLVCHnNXpM0udakK95GmGrMe hwsw== X-Gm-Message-State: AA+aEWbuM297WVIAlpj97IQzYH2636W8lu0rHS9JznVtb6hiNqBRTlPR 6nzcWTNHnq0F2iZOcn6gajRFhwur2ls= X-Received: by 2002:a37:b084:: with SMTP id z126mr30666051qke.154.1543358593549; Tue, 27 Nov 2018 14:43:13 -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 d32sm3226108qte.36.2018.11.27.14.43.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Nov 2018 14:43:12 -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 V2] thermal: Fix locking in cooling device sysfs update cur_state Date: Tue, 27 Nov 2018 17:43:11 -0500 Message-Id: <1543358591-25189-1-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Sysfs interface to update cooling device cur_state does not currently holding cooling device lock sometimes leading to stale values in cur_state if getting updated simultanelously from user space and thermal framework. Adding the proper locking code fixes this issue. Signed-off-by: Thara Gopinath --- V1->V2: Rearranged the code as per Daniel's review comment drivers/thermal/thermal_sysfs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- 2.1.4 diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 2241cea..aa99edb 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -712,11 +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) - return result; - thermal_cooling_device_stats_update(cdev, state); - return count; + if (!result) + thermal_cooling_device_stats_update(cdev, state); + + mutex_unlock(&cdev->lock); + return result ? result : count; } static struct device_attribute