Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2768419imj; Mon, 11 Feb 2019 08:11:05 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaj0SbAENurI1XCDlJeqJ2nVPnwxvFMFRFpKzMPoG6nnn7i4f69whYhY0uaU0O5wlgBB7eg X-Received: by 2002:a63:65c7:: with SMTP id z190mr29475031pgb.249.1549901465529; Mon, 11 Feb 2019 08:11:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549901465; cv=none; d=google.com; s=arc-20160816; b=VXBuK/8MlIiAmluD6g/uAelg+OFDL37wDM7Zrr47C+lo72ceVSMMhlvvEqLXcr8Eyx 9ByolqzhFwKZ5IjwmN3IdvJ1hZGJcg8KdyP+MRef+c/FhrDjwK68LRYquYDxUD4mBzRO pAmx9J5LdO6DFKGpV9xnPLj+35NbYIXaDZopFgqbG3AfXKu8Qqjz9zhQr67PWeV+2ymm FfCyUm1SQz1N4o5S5DARiwQIsX0ROzoRLr4EGYzup/xkjCu8WRpgbYVmZCP9u6sdavdN JJspIkDl0aGIdy77T1UW+cyI/+6C3SJbcwyusQBof5LLXcefVSjgyrJXgdpw8NNcFpad 3dZQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RxpwNCwSfY7D8jiNzglh3cxeRA969sf8lQfR8Z3MeIM=; b=mfHYUFNsZo8LAM9+5WogNYQQsHwD7AKwnz5XVTFmnQkN/Xc1GeXu1zNl8xz8ImyFAf OCi/tyPOOD8hvazr4JOPdZiOKy86DlPykYZkxtaWU6XeT4lnFwMLHyyq4fDy3Ti8nCrf OqTm63ThnxRQvIk65oN3o8wZE+Py9vB9sxN8Eh5joZ7fN0JwxvZDQyjsSacdiS4+gVm4 kJ/xdwywAIKJwhwjHJC/BqS7I1cnkvZxQ9yjMEtJzRa4E6xsGZd5SeG8yHsr+SpT/1uf MuspU7ZqKFSDVu/gynkebuDhdgnwP67X5A1LjQspMxUEZ2XEb5EsYBI6FBVBz3qovbBX eIZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TxvWU8d4; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si4426641plb.200.2019.02.11.08.10.49; Mon, 11 Feb 2019 08:11:05 -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=TxvWU8d4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729330AbfBKOZI (ORCPT + 99 others); Mon, 11 Feb 2019 09:25:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:58422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728284AbfBKOZF (ORCPT ); Mon, 11 Feb 2019 09:25:05 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A491420821; Mon, 11 Feb 2019 14:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895105; bh=RqXEecHFDKiNEipWvm3W0Z9ee7U90ah7LNRDdk1sa70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TxvWU8d4PZ93BxjT4dKbJEWp6fo2AMAuxodK5pd6sdgipfj0xMohUt1WEsAfX9Roj CKZysntmKnrAHHXM1QfmlTo3ME/WrzohqIfAm8JN6rIUTtUhmo3+7C+Ux+cfzJQ5AT d5We9gKQc5GHuCzYvJebjngCxeYEziWt65RiZqUc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thara Gopinath , Zhang Rui , Sasha Levin Subject: [PATCH 4.20 094/352] thermal: Fix locking in cooling device sysfs update cur_state Date: Mon, 11 Feb 2019 15:15:21 +0100 Message-Id: <20190211141851.856039832@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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