From patchwork Tue May 31 06:31:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143525 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8C1060761 for ; Tue, 31 May 2016 06:32:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCBE02821C for ; Tue, 31 May 2016 06:32:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B182928213; Tue, 31 May 2016 06:32:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56BC527D17 for ; Tue, 31 May 2016 06:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162137AbcEaGc3 (ORCPT ); Tue, 31 May 2016 02:32:29 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:33290 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162127AbcEaGc1 (ORCPT ); Tue, 31 May 2016 02:32:27 -0400 Received: by mail-pa0-f65.google.com with SMTP id f8so24025993pag.0; Mon, 30 May 2016 23:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nQJVmA/CCSP/Tu4H47w6LPuUcIYe8GV5R/ZvqmsQ5SM=; b=RW3dCgMWwW9IW9Q4t45GP1GrOZ5FrciHaP6w03n8+M6/HM+F5iun2B+fz6X5QUeGmt VjPkvyHyGIN1EdWDLQtUXpLHtwwrjKmhaHpGEODXJHAQOl2W5nUvVOCr5LjWPzFcmk4g qWk2dOs1SNzIqOq2mhR80ioegARMk/PCTWsg+P1etguXdeso8q26LHW+2QxVdL4cPYo0 Ex2YqCErQrWbznnQEVSYhR1sz5PusnGkpKhImtocArxCkRjiePiYFl6rJ1/v6vGUH4NI 1zRvcB+W7j3paciV6S4A1pdiPOQRP34enfJe2tFOX18iI7QZUATQAaElhTO2ejKaM3aq XmCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nQJVmA/CCSP/Tu4H47w6LPuUcIYe8GV5R/ZvqmsQ5SM=; b=Z/JTwgm4yPFpg7cg3HFwZMbEX8mzvrPOXCs9UFjS7Y7eJzX+0igWSiCMDCAvbCA/QS RTI4VKRIMGLUBCmqetAlMetgs9xWVJdwWfO4rjB30nQxbmmSiUrPlw7+b9ZKl1WkgZSN rt7MCDnDB3b8BO2ZTaim2uzifX4Pe7UZKpO446VqDJg5VnaeN7L0skv0dBh3TngGDQ5t 0ycJRUgPatET6D4TO6+/uveejFT7fhHb+Me/PtCm66eXzj2aZvN0NjdvKAMqa/UpPALX 3o6XBI12p2078WnH3trQG1r5peiHjxB6J4zscGwcEiNamO03R1MPNPvNqMarKDjzMK8q 1Yug== X-Gm-Message-State: ALyK8tJ+P81jJQsIEbFdiT4ZC+zDX81P5DF8Z3QLToziRoB+GUBaKCjGUHmTLVYCVOIwjg== X-Received: by 10.66.138.16 with SMTP id qm16mr52841212pab.28.1464676346478; Mon, 30 May 2016 23:32:26 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id o2sm37185648pfi.85.2016.05.30.23.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:32:25 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 11/15] thermal: sysfs: lock cdev while accessing type Date: Mon, 30 May 2016 23:31:32 -0700 Message-Id: <1464676296-5610-12-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464676296-5610-1-git-send-email-edubezval@gmail.com> References: <1464676296-5610-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Serialized data access to cdev->type in user facing sysfs handler thermal_cooling_device_type_show(). The existing cdev lock is used. Updating comment on the lock definition. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_sysfs.c | 7 ++++++- include/linux/thermal.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 86a77cd..044090a 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -682,8 +682,13 @@ thermal_cooling_device_type_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_cooling_device *cdev = to_cooling_device(dev); + char *type; + + mutex_lock(&cdev->lock); + type = cdev->type; + mutex_unlock(&cdev->lock); - return sprintf(buf, "%s\n", cdev->type); + return sprintf(buf, "%s\n", type); } static ssize_t diff --git a/include/linux/thermal.h b/include/linux/thermal.h index fa2c2be..7b2c014 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -137,7 +137,7 @@ struct thermal_cooling_device { void *devdata; const struct thermal_cooling_device_ops *ops; bool updated; /* true if the cooling device does not need update */ - struct mutex lock; /* protect thermal_instances list */ + struct mutex lock; /* protect thermal_cooling_device */ struct list_head thermal_instances; struct list_head node; };