Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3707712imu; Mon, 28 Jan 2019 09:23:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN4MZCHEcV6v1eEG7BKyKz+uYwhHuzqrnWRuPOnneEQsGupG+jqy0ZvGsL+XCdf5UiydLyIe X-Received: by 2002:a63:a452:: with SMTP id c18mr20751846pgp.204.1548696180922; Mon, 28 Jan 2019 09:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696180; cv=none; d=google.com; s=arc-20160816; b=EBp2D228YsWgpYzqCD3bdD5FvaLROPK6uiG19FlP8Sb9cxjku0H2xBytXlVY47LIj4 WJAb6EG/ohOjtF0YLpKhTYFmoc+RGMADejs2ivkkXFtW4UJcDqjZKDMGscay0TMFBYQH I7bblywQuC3ymiv1CCBkl/be3jfezkvaOXluPCtzFl/Brvfw1cHtzqL/gb4bIL5YQrFE Q7Ie1qquK73jS+si+SLaKhjhRz/lG/RvX73bri5eu/POHbNpkOi2Xa/ZS+siZJmM6VrR GmdDbA4KiE5xfxxzhxvB74AnNzrEva9z/LuGe9h8GYhNzV4Vb95LbNzs31iNpp9pAn7H OMEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hOpmMOHx5IXN/vbxAV1+KNUwycdxc0DQAL5fFbPQycQ=; b=dZ+osF5G1lrcaL8j38Zh2CwxEQ3SNVB/o0m5hAlJvxkzJe3IlR5+JBjO0t4u2QV6r6 ff9xS67JVC8FKY4mcap9RbmlNGWt3fGZHyJERAzvuys75jkXZVHMm1DI/fw0dWU6jhHd nVy2L4HcIrdo38kZ9rA2vjvpSlIYjtCxvLUKJn2tNmfVUbk2LBjvuWMGnuPBuJjQfg0c ynYNqpcEFyFm14zBEZt3882q/dSqEh1RtCiq1eonNCEITEULtbp2p3B/aNUXJO1Ee2zX 5Px1TxCzsyGIOsWlK0qZQ3teNVLdWES5b35vW4KiMZmIejMWfMvv0dfv3dDAcKWhpDTY +XYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wN6fv0i2; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si11257942pfj.162.2019.01.28.09.22.46; Mon, 28 Jan 2019 09:23:00 -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=@kernel.org header.s=default header.b=wN6fv0i2; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731433AbfA1QDj (ORCPT + 99 others); Mon, 28 Jan 2019 11:03:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:48866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728431AbfA1QDc (ORCPT ); Mon, 28 Jan 2019 11:03:32 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A5BFF2175B; Mon, 28 Jan 2019 16:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691411; bh=pewgAzwiChmQ6h5N8DxneNyd4MjiXIqmOpt4mZR7ODk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wN6fv0i2NqaeEoTyUuTix0rCkZjK6aSPqqNo3CldEIY3inwp9/uV6+5qSLsfL9RXs OsSYOLGbLjiND93B/0RoNgHvAIZPj/ja93NZgJSEITuX3uhoQI/r/JoAfVA4Y1xt1a mZrDBQqBgaeqhsxz1XOXBZZQevZ9DaXpHBOdNtvU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thara Gopinath , Zhang Rui , Sasha Levin , linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 087/258] thermal: Fix locking in cooling device sysfs update cur_state Date: Mon, 28 Jan 2019 10:56:33 -0500 Message-Id: <20190128155924.51521-87-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thara Gopinath [ Upstream commit 68000a0d983f539c95ebe5dccd4f29535c7ac0af ] 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 Signed-off-by: Zhang Rui Signed-off-by: Sasha Levin --- drivers/thermal/thermal_sysfs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 2241ceae7d7f..aa99edb4dff7 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 -- 2.19.1