From patchwork Wed May 4 06:02:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9010601 X-Patchwork-Delegate: rui.zhang@intel.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 E1692BF29F for ; Wed, 4 May 2016 06:09:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1908F202EC for ; Wed, 4 May 2016 06:09:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32233202B8 for ; Wed, 4 May 2016 06:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757106AbcEDGDD (ORCPT ); Wed, 4 May 2016 02:03:03 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:33564 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757079AbcEDGDC (ORCPT ); Wed, 4 May 2016 02:03:02 -0400 Received: by mail-pa0-f52.google.com with SMTP id xk12so20283437pac.0; Tue, 03 May 2016 23:03:01 -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=oW2VRTI/cpWCvlTaQyIGpGw9BtABK7sxh0riAl+ZuKo=; b=JMq01SP/xqUEgoY/a4uEG2gNKlbh0BBDWRPrFEL2Q9ZlXQcwLazgefnSjeEjIAwt7X qK/n/ypwB8Wrh2UKTJizaWqMKSvgD1NB4ql6R3AzlvRx1OvBj06CLv1ZwWvYsuSCstdJ 1aY5PvS8YxFA503o6DvEVNwzS2+ZrY12PG6y08hJCMifr+fPK/ALksVucNTCTyUG46NK fxYKTIxakgPl7W8Uj2k0WZ9e++tC+8PzqVHaDVRqlTqwOcG8rRCagbDBZ1eR7y6tOnSF OOYM1QLvl2nJLMtUDNvpc4OsSpUSMJrPKlHFRAaVrq4kIe7gDTGDiRBIDsycB0nLNNrx nMvg== 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=oW2VRTI/cpWCvlTaQyIGpGw9BtABK7sxh0riAl+ZuKo=; b=j8E/fbsuK3jxO2vbnMCTthLpFAMFkMVyQk3FoO/wAjSSh77boJbEhCFKJwpSQo6JPn Ng8QoSGu+rnHw9gcYIOtrfNbzPwVj0jnDCvv0M+/E+BjY+kna1KpL73UGwstl/QTx3/4 r/aFLjTKfk06r6tQzohjSVUkxsraAFeQ06hyPjU7gFqXIx0QegqwYh9H7wK+eJ9e86K/ vffz7AkNc6BMEnSyUhv6+JkGLIxOz/ldOeDdwf9vqXC4UNUqnh4v3ItcSZlbsmk0Xx6W OeMCm4tQsYICTHkambhsF/JQ5m7sOOzxce1OTycP9YJrPno9wIZfF8QnWSxLU7yKPm+y SYdQ== X-Gm-Message-State: AOPr4FW1bRdj1E7sG/sUQj42NZw4W2HetAz29NfHoAxyqNEbe+hWk6iAFkPs3SNX69xsFg== X-Received: by 10.66.193.161 with SMTP id hp1mr9594502pac.9.1462341781264; Tue, 03 May 2016 23:03:01 -0700 (PDT) Received: from localhost ([2601:647:4203:c8e0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id zs16sm2649802pab.13.2016.05.03.23.03.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 May 2016 23:03:00 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 06/31] thermal: core: move mode attribute to tz->device.groups Date: Tue, 3 May 2016 23:02:20 -0700 Message-Id: <1462341765-13268-7-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462341765-13268-1-git-send-email-edubezval@gmail.com> References: <1462341765-13268-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-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 Moving mode attribute to tz->device.groups requires the implementation of a .is_visible() callback. The condition returned by .is_visible() of the mode attribute group is kept the same, we allow the attribute to be visible only if ops->get_mode() is set by the thermal driver. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e32f851..6e44038 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1006,6 +1006,7 @@ static DEVICE_ATTR(sustainable_power, S_IWUSR | S_IRUGO, sustainable_power_show, static DEVICE_ATTR(mode, 0644, mode_show, mode_store); static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store); +/* These attributes are unconditionally added to a thermal zone */ static struct attribute *thermal_zone_dev_attrs[] = { &dev_attr_type.attr, &dev_attr_temp.attr, @@ -1028,8 +1029,34 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; +/* We expose mode only if .get_mode is present */ +static struct attribute *thermal_zone_mode_attrs[] = { + &dev_attr_mode.attr, +}; + +static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, + struct attribute *attr, + int attrno) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct thermal_zone_device *tz; + + tz = container_of(dev, struct thermal_zone_device, device); + + if (tz->ops->get_mode) + return attr->mode; + + return 0; +} + +static struct attribute_group thermal_zone_mode_attribute_group = { + .attrs = thermal_zone_mode_attrs, + .is_visible = thermal_zone_mode_is_visible, +}; + static const struct attribute_group *thermal_zone_attribute_groups[] = { &thermal_zone_attribute_group, + &thermal_zone_mode_attribute_group, NULL }; @@ -1868,12 +1895,6 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, } /* sys I/F */ - if (ops->get_mode) { - result = device_create_file(&tz->device, &dev_attr_mode); - if (result) - goto unregister; - } - result = create_trip_attrs(tz, mask); if (result) goto unregister; @@ -1990,8 +2011,6 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) thermal_zone_device_set_polling(tz, 0); - if (tz->ops->get_mode) - device_remove_file(&tz->device, &dev_attr_mode); remove_trip_attrs(tz); thermal_set_governor(tz, NULL);