From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 539C2C282C8 for ; Mon, 28 Jan 2019 15:48:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B3CA2147A for ; Mon, 28 Jan 2019 15:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548690480; bh=pewgAzwiChmQ6h5N8DxneNyd4MjiXIqmOpt4mZR7ODk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=r5TbQBMdbqdpxy8EV819gQlD3kSiG48CL5lwLSMS6NEciiw5EueXYP7q1rVzVgUdc il410wK4gUUdUUXoINBD6HmixYexsPsb4U5WTiv2GfB8GBa/yqOvd0nSpgkrTUapPN sNmwxZCc49NE0OHc4RY30xcWrgRm5OKIJpZeQtlY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbfA1Pry (ORCPT ); Mon, 28 Jan 2019 10:47:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:33298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728381AbfA1Pry (ORCPT ); Mon, 28 Jan 2019 10:47:54 -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 D06122177E; Mon, 28 Jan 2019 15:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548690473; bh=pewgAzwiChmQ6h5N8DxneNyd4MjiXIqmOpt4mZR7ODk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FsJfyDERUxRgPEIZ7s2xQI8i4bp09PWQizjJersntpqsxtlXMkL/8Zg9rrDXBZoL4 q/1WXAeoXNHhwfQfm+oeppAzq8HqCW863Y/GbPO9z9TW14G8LW8PMp038AteIrCGsn c4xH6bWyoGBa0TuZGFxnyYb4dzqRqK/Qjvjsbwq0= 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.20 101/304] thermal: Fix locking in cooling device sysfs update cur_state Date: Mon, 28 Jan 2019 10:40:18 -0500 Message-Id: <20190128154341.47195-101-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128154341.47195-1-sashal@kernel.org> References: <20190128154341.47195-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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