Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp370149imu; Wed, 2 Jan 2019 22:31:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN7f4lWHy1z1jU3yo884J2FGSJxbTftkxyqVZtydzwiodMcumgl472JgmpHM6Au+x8qc/Rla X-Received: by 2002:a17:902:8c91:: with SMTP id t17mr44652798plo.119.1546497068902; Wed, 02 Jan 2019 22:31:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546497068; cv=none; d=google.com; s=arc-20160816; b=mG3uojZqQhdsYSc0mNXODs6tS68xFAIrQ3jOPLHGch/WNnrh9iK1WPAyegmWA2UOSp V8vRCBdu6fSEAc5o66otdgVCmXM67xxQKnFsQlKUrh5kDiEQ0Vd8QbsyWTNBD9FADa1s yjJcQMkz/zr3w9UQxNlLEpb8uT+U44OxmTjzAzx6mUwKWRY7HQNpRFeIoxhHZJH/x91n e53yZs0rYho7gBDuFFo2x8BBdjye6yS19nfn1KCX+j6dY9NlbaBJFfergaEtLOxAjR+M voY/la/+Qjs2rc6zXaehmulvUA74OTA3Hzp2SFcE4snfgcQkDOUBxR3/flRxheUw7LPP biOA== 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:date:cc:to:from:subject:message-id; bh=tLBH6Di7GzMQXwzlTFCZC+p3+KjgqzN0+VHwJIf1lL4=; b=fcBVe9RHkihtw8Y88UpiVfG8lSZHpmOcwD3KVGO8T5NL2qIhKB18E+jhlzvdx6TXXt 168FCCQbATbp6SyPTd0Vb7VY8FYYX4YTok4N2aJbsUpQkHz2BMILUja7Arj6mPgaZCR3 XbU9Tt+ghlvT+Pc2OgoTQXsJJXDCFrlRnALIBcwJjmcs7IQLigiNZwQUuqDY2iC24vqB MX1y4DJgz5TubA1JJwDwT7Yd9SoAJfgx4+XIb6+lOxL6p/Fv7yjF4UpwppWkSwlZHOI6 iUpZM4UABEV8Z3VIWFHgWnSFVG25gIVnNEanWvCp6Mrx/hCAJzbf4z4gJufnC2YAS1om IhWA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a16si6994600plm.365.2019.01.02.22.30.53; Wed, 02 Jan 2019 22:31:08 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729083AbfACCv0 (ORCPT + 99 others); Wed, 2 Jan 2019 21:51:26 -0500 Received: from mga09.intel.com ([134.134.136.24]:39257 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728132AbfACCv0 (ORCPT ); Wed, 2 Jan 2019 21:51:26 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2019 18:51:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,433,1539673200"; d="scan'208";a="115046330" Received: from dliu15-mobl5.ccr.corp.intel.com ([10.249.175.141]) by orsmga003.jf.intel.com with ESMTP; 02 Jan 2019 18:51:24 -0800 Message-ID: <1546483882.2077.10.camel@intel.com> Subject: Re: [PATCH V2] thermal: Fix locking in cooling device sysfs update cur_state From: Zhang Rui To: Thara Gopinath , edubezval@gmail.com, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 03 Jan 2019 10:51:22 +0800 In-Reply-To: <5C2D7376.3010408@linaro.org> References: <1543358591-25189-1-git-send-email-thara.gopinath@linaro.org> <5C2D7376.3010408@linaro.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 三, 2019-01-02 at 21:29 -0500, Thara Gopinath wrote: > 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 ? > it's already in my tree, and will be included in my pull request which will be sent out soon. thanks, rui > 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 > > > >