Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp355425imu; Wed, 2 Jan 2019 22:06:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/XpA6Fd9fP4rBNTJRawV6EJH0X1cS3vEZGttAOqpwtYFfNWByXmuU1Xtaz+K09NBY3KZvbW X-Received: by 2002:a62:3c1:: with SMTP id 184mr47545792pfd.56.1546495603080; Wed, 02 Jan 2019 22:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546495603; cv=none; d=google.com; s=arc-20160816; b=uUxCCPo5mf/JBRpaSrbASox/nHtynMaFqRhFCeJgrba9sdTZbgH4DgBS7TB6A1ewW/ 6druZY6/pSprO+UqAkVKVQDDMA0U30EtcdHqDryRntvlQ72Utbqy+VYKz/9Qkt3d0m/6 PyaoJdnJLN5zfNzvzEoEnX+nZyiTdIPLSwo/6ydLFmK7irXhg4d6eZoDGk2Iq89XF4uu RBjoVF+yDcZYgpdYRPr+O7Zqy+X3Crpkgm4xMgLRTXgc/DViJizUu8xe40dnfUK7ivrM 9LuLzeE9G9F1R73jz3CiOSvwGNi87JzX3sbI++ggvkJsDGlaI07tPuc1AvUF3waRcAS4 ZBGA== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature; bh=BOCxujPQqSYNW7EN8vihehSI7jwqabnkraHEDNVAbAg=; b=tIMCX23thGWkx7S8ga8rJC/yGsdazTynW/2JIcM6UTfRrxl/4ecfW6Y6stle33KYj1 yicD7T0edNGdibGNE3P8+gf78Phgh/JVw0LHupzROnQuafSYOjbjcfcj5M79GmYbeLQO B8HAM1Vii4PqB58s1bIS9L8GL1sbqtXirz6lAI1WpUE+D+62H7rCtftHhqvYdZvbN0Ol gkkrsu2iR0Kjp6hLSyprzfFrfXnuqME9CdAXkBTRSkOYwQ2kVQxqpupTRa9cmEbbhWFe C8mY3elK2ccTv0MZ91oyyKK19CoJyNBmuiZ/Kppt7Ey3/dAUT5uPK0gPNT5QaqfsCpxS by1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H46QzjC6; 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 f95si9652300plb.60.2019.01.02.22.06.25; Wed, 02 Jan 2019 22:06:42 -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=H46QzjC6; 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 S1728228AbfACC3O (ORCPT + 99 others); Wed, 2 Jan 2019 21:29:14 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40177 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727511AbfACC3O (ORCPT ); Wed, 2 Jan 2019 21:29:14 -0500 Received: by mail-qt1-f194.google.com with SMTP id k12so35542230qtf.7 for ; Wed, 02 Jan 2019 18:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=BOCxujPQqSYNW7EN8vihehSI7jwqabnkraHEDNVAbAg=; b=H46QzjC6NxE3D5FJGQieQHjJtaxcXaenJ36GuhPCpx0NRlpkFEqMhNuMtZk2VzhW0c 6aUOBiH7PQS1S+OgxBjKPKYvmK+YU4MT9cjX6oZ1I7MkOIXkW+tFJEzki7wOHe0hmYNz rDR2zkzCqxnuU3KbrbzI6VHWVU8Si2bRT3lR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=BOCxujPQqSYNW7EN8vihehSI7jwqabnkraHEDNVAbAg=; b=QBo6+5WoafidAlrQwi28T/G0i4QRJjZlGMx1+LvDOs2PnGcbQwU+QcAAYx5FApjfHJ ycIHIAiF79Fq79GZHQlJ4w8PZuPb5OuKfyCXk/l0JWL2PV56s35YGGcBiXbLbszY8OKa fOW9HtfCUUYanE6RPnlYRZ7tQYZHbD/e50X7r3jdWEgAPYdP+oawxIz0ULuPfvI9dqkF YtLXG3NF68dV7t/EDNUnhPFTerPzzdU3SBKjJ2+8LZrKsAlUrbSp40HjiSbIECCaPJC8 jCyh6QivDBpllafuIliKV5amPn8Pej9GLGxlmg+R3dEn8yY7NVmOjdioB6pU+pw62tA2 3JFg== X-Gm-Message-State: AA+aEWaWAYfbnDD55QkC6Es4V/Muz9LQRQL/7lbCQSomwN0CBQLPRCxF RrB+eW7w+Z0sFfLzmGgX2isDZGRK/3E= X-Received: by 2002:ac8:674b:: with SMTP id n11mr43712546qtp.104.1546482552553; Wed, 02 Jan 2019 18:29:12 -0800 (PST) Received: from [192.168.1.169] (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.gmail.com with ESMTPSA id v1sm25458220qtj.68.2019.01.02.18.29.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 18:29:11 -0800 (PST) Subject: Re: [PATCH V2] thermal: Fix locking in cooling device sysfs update cur_state To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org References: <1543358591-25189-1-git-send-email-thara.gopinath@linaro.org> Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org From: Thara Gopinath Message-ID: <5C2D7376.3010408@linaro.org> Date: Wed, 2 Jan 2019 21:29:10 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1543358591-25189-1-git-send-email-thara.gopinath@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/27/2018 05:43 PM, Thara Gopinath wrote: > 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 Hi Eduardo, Daniel Any comments on this ? Regards Thara > > 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 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 >