From patchwork Tue Nov 8 05:08:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416565 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 ECD6760459 for ; Tue, 8 Nov 2016 05:23:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCBE028B9B for ; Tue, 8 Nov 2016 05:23:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D046F28B9D; Tue, 8 Nov 2016 05:23:07 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 8212928B9B for ; Tue, 8 Nov 2016 05:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752900AbcKHFWv (ORCPT ); Tue, 8 Nov 2016 00:22:51 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33006 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752881AbcKHFWt (ORCPT ); Tue, 8 Nov 2016 00:22:49 -0500 Received: by mail-pf0-f195.google.com with SMTP id 144so9724237pfv.0; Mon, 07 Nov 2016 21:22:49 -0800 (PST) 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=96N6w+AOx8HQB/8Kj9NzWUiN/I8qsT3/qTK9M9bKk34=; b=rg9HCTAs4WkftKqdRZz/szyk5JUHQZNgft8nZK4MHOx6t77FSbY9dxJeCDekoxhSz9 8ERKw7nCf+a5gUU/+Wzv6LGeWT5eL+v1dxpuN8SWgWZvY0YjDWb1Z+QisO0NqgcdOKeV SCKQVxHyS8KSH/mGQZVnY9Go+/mnrn7DtmWKDcq+2Qc678bCghnbBCsEz3+C+S9HHf23 Yu/PksWEm5Uwh6ime84lGeVZJUYjG/nW0p6PQQI6fH6QYuQ2UdwksKXefb5Ak6l3EPQ4 0WO4HpWc42laQlHV37gzMCj/nfnbfi/Z36+f3MNpGSsKMx0D/knxW9O6D3DMHY92YCAl RLaQ== 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=96N6w+AOx8HQB/8Kj9NzWUiN/I8qsT3/qTK9M9bKk34=; b=TfknEDfX4HW67XD6BaRG/YNVuMA9ocgLU/+1iogb5XUpv/gXuegeA7r4xDKFLSd1bw 3v64p5pxm+7ntciSEHLCX4BJH6HMA5QTxw5J3OW3REH7NUPwjjwVLLjXzh8OcDyHYbq8 0Tqk+CDtOhOpJnes5Zlt2oWXF6TpuOsdHMe/diOORV/wkRnE6he9PErfgGhAO3FVzoi0 0lZFszu6klHGmbwqL6VtjDmM1pRi74xUF7XUnDu7Z4LTgHQ+ae/d7P28/AWVw8+Jd7Km CDzXpw/xY+hjrw+yFzOdbphSuRB/ZTfGrgjOi5xn4OXb1QZu1zJySedJIGaeZgv7PVKn DlOw== X-Gm-Message-State: ABUngvdkwPinWrMJTyxpPVpCBamLIknARDwTpln2Hjh/ptL/q4nzpTgf7cVQNJ4UoWPD4w== X-Received: by 10.99.159.17 with SMTP id g17mr16175117pge.149.1478581786800; Mon, 07 Nov 2016 21:09:46 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id x90sm9127483pfk.73.2016.11.07.21.09.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:09:46 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 06/49] thermal: core: move mode attribute to tz->device.groups Date: Mon, 7 Nov 2016 21:08:44 -0800 Message-Id: <1478581767-7009-7-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-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 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 | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index ec15a60..ec8551a 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1064,6 +1064,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, @@ -1087,8 +1088,35 @@ 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, + NULL, +}; + +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 }; @@ -1932,12 +1960,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; @@ -2054,8 +2076,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);