From patchwork Sat Feb 21 02:10:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 5859001 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 687FEBF440 for ; Sat, 21 Feb 2015 02:10:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C01F62055A for ; Sat, 21 Feb 2015 02:10:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA4602053B for ; Sat, 21 Feb 2015 02:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754916AbbBUCK1 (ORCPT ); Fri, 20 Feb 2015 21:10:27 -0500 Received: from mail-ig0-f169.google.com ([209.85.213.169]:50276 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754796AbbBUCK0 (ORCPT ); Fri, 20 Feb 2015 21:10:26 -0500 Received: by mail-ig0-f169.google.com with SMTP id hl2so10908915igb.0 for ; Fri, 20 Feb 2015 18:10:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=3htwNtcTz7CK7eMe0YlEUSHz7UReEHQXwEq4GlAk+5c=; b=RQfGXewuG1alpKmsNVaVsAlwY+wABn/kkHXiawtAvu9ifFqHSGuv4Eg1uYabW6ZZo7 3PoLe7O8lrHCPjQsYU6tpWTySAD0whHucOSZbfYC25BtMvb/qbM0pASMLnNTC/fKkYEG EvPZJYFeq+Rxxv9qeFhetg9eMyxxkDsM75CQo= 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; bh=3htwNtcTz7CK7eMe0YlEUSHz7UReEHQXwEq4GlAk+5c=; b=Th1zVInrU3OU8zZRcuVSujzfkvdpRnArgwvYWzNSfv4K693f2BQCGjf+QLcBXZu8SS T7JGz9TE5o2cR0thTs29wowxGU29qxDcPxYtSDnbgJtbauYaRDEOCWnSv1b9by68pdwk zwSximIbiP9dYQPIWuqT4+U0G1UaTRLYJ1xsnyBSzHGAeSN01XoQ/4D8TmU/8KNiXhXd Aan2K9in+UTJs+92TBazf4J+Frau7j8lTFR81zHg0zLY4as+j26PbkR2uY6ivAzsPE5C edGe4Q0dN2HM54PBa8oaCYuM5gvEhr8HCXy2rN/gESNLVjVbz65TaChCl4Es0Z3jwZeU b7Ng== X-Gm-Message-State: ALoCoQkEWmjrv4Bemwz4QaFT2foUcpUml+vhf0rcFx8Rh2DTeCGDBtk/F54+DeIaALriTj0Mb6xJ X-Received: by 10.42.83.147 with SMTP id h19mr886335icl.95.1424484625790; Fri, 20 Feb 2015 18:10:25 -0800 (PST) Received: from mka0.mtv.corp.google.com ([172.17.73.37]) by mx.google.com with ESMTPSA id 5sm2039555igr.17.2015.02.20.18.10.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Feb 2015 18:10:25 -0800 (PST) From: Matthias Kaehlcke To: linux-pm@vger.kernel.org Cc: Zhang Rui , Eduardo Valentin , Matthias Kaehlcke Subject: [PATCH] thermal: Make sysfs attributes of cooling devices default attributes Date: Fri, 20 Feb 2015 18:10:08 -0800 Message-Id: <1424484608-20181-1-git-send-email-mka@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Default attributes are created when the device is registered. Attributes created after device registration can lead to race conditions, where user space (e.g. udev) sees the device but not the attributes. Signed-off-by: Matthias Kaehlcke --- drivers/thermal/thermal_core.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 48491d1..174d3bc 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -899,6 +899,22 @@ thermal_cooling_device_trip_point_show(struct device *dev, return sprintf(buf, "%d\n", instance->trip); } +static struct attribute *cooling_device_attrs[] = { + &dev_attr_cdev_type.attr, + &dev_attr_max_state.attr, + &dev_attr_cur_state.attr, + NULL, +}; + +static const struct attribute_group cooling_device_attr_group = { + .attrs = cooling_device_attrs, +}; + +static const struct attribute_group *cooling_device_attr_groups[] = { + &cooling_device_attr_group, + NULL, +}; + /* Device management */ /** @@ -1130,6 +1146,7 @@ __thermal_cooling_device_register(struct device_node *np, cdev->ops = ops; cdev->updated = false; cdev->device.class = &thermal_class; + cdev->device.groups = cooling_device_attr_groups; cdev->devdata = devdata; dev_set_name(&cdev->device, "cooling_device%d", cdev->id); result = device_register(&cdev->device); @@ -1139,21 +1156,6 @@ __thermal_cooling_device_register(struct device_node *np, return ERR_PTR(result); } - /* sys I/F */ - if (type) { - result = device_create_file(&cdev->device, &dev_attr_cdev_type); - if (result) - goto unregister; - } - - result = device_create_file(&cdev->device, &dev_attr_max_state); - if (result) - goto unregister; - - result = device_create_file(&cdev->device, &dev_attr_cur_state); - if (result) - goto unregister; - /* Add 'this' new cdev to the global cdev list */ mutex_lock(&thermal_list_lock); list_add(&cdev->node, &thermal_cdev_list); @@ -1163,11 +1165,6 @@ __thermal_cooling_device_register(struct device_node *np, bind_cdev(cdev); return cdev; - -unregister: - release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id); - device_unregister(&cdev->device); - return ERR_PTR(result); } /**