From patchwork Tue Nov 8 05:08:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416609 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 8251E60459 for ; Tue, 8 Nov 2016 05:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7347028B9D for ; Tue, 8 Nov 2016 05:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6843128BA3; Tue, 8 Nov 2016 05:28:10 +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 1214A28B9D for ; Tue, 8 Nov 2016 05:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753625AbcKHF1w (ORCPT ); Tue, 8 Nov 2016 00:27:52 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33628 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753614AbcKHF1u (ORCPT ); Tue, 8 Nov 2016 00:27:50 -0500 Received: by mail-pf0-f195.google.com with SMTP id 144so9736515pfv.0; Mon, 07 Nov 2016 21:27: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=qSDnwqYf944DKuc/4MwRMBLee6ozzv0lq37YNFNH0ls=; b=A3mJ8j48f3qae42/faf4cqz7DXezQ5jlq/r0YjTSBnR06+nNcYamzuHxUkC1zV0ShE q62WsxPEG2O7E3o5IcR0o86+0ZIEr7RFC8WLikm6gAAsfoKtib+hql+4NoHg7X7b3nsK qO75Pe5Is4MAqscUFnSFhzITzF/s5mhe0/+iPWdaZdFR1LGxWZIzGjICEcpSP7F/F9NE dOlB4SMWbbNPkLFJ/7Nypy8lJXKL0EZ60N6D87cfB6Il8IVR21LxWu4Y3d58fCnhNttP djS1JZylpwE90VdOGAEBE9mWJljoZgkqPYtU+E5dvP8KZgRa6iQnrMUdAxY8+IVvygRA X7Rw== 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=qSDnwqYf944DKuc/4MwRMBLee6ozzv0lq37YNFNH0ls=; b=K2Qy8b7B3KRDxzMjJHdkVgs6MEkFN0XMcfexwvn/STqdWHF59IXiUFJ2ohAL99COiH SG4U3HEWlZahpnsOSZIM4D1nsIHqCBLBlHMMqqGGyvupZwWJpCJAwIJPHybeFZMZTRht bKnSt9d8zFqAVwY0O0/7rI912qzWjVmu5xd+l8uK+TtIXe1PZ+dRkYcdOtmTtzu9KVqo oT3Ss6iamTD8Zb5C43JGu1nPAPNQxEr0eCGz5X0b6PiXMY8PhmBySDIpW1Yc5X+Ds5tX qGoyXM5xbmTH3X9Gc8jtpwSu9jSuBtZAo/vcyfKv9RU4ZKrHYC1Tz9CNBzZIA1mNzqRM dtSA== X-Gm-Message-State: ABUngvcRCvzGovZSL52RJD4a2X1fdK1HZYv3wMYxm3eo07gXLpxjiXwZAxj97BUOM2ceZQ== X-Received: by 10.99.181.10 with SMTP id y10mr16120546pge.161.1478581815823; Mon, 07 Nov 2016 21:10:15 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id ix3sm44612592pac.17.2016.11.07.21.10.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:10:15 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 13/49] thermal: core: create tz->device.groups dynamically Date: Mon, 7 Nov 2016 21:08:51 -0800 Message-Id: <1478581767-7009-14-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 This is a patch to allow adding groups created dynamically. For now we create only the existing group. However, this is a preparation to allow creating trip groups, which are determined only when the number of trips are known at runtime. 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 | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e399ae6..971f033 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1236,7 +1236,7 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = { &thermal_zone_attribute_group, &thermal_zone_mode_attribute_group, &thermal_zone_passive_attribute_group, - NULL + /* This is not NULL terminated as we create the group dynamically */ }; /** @@ -1347,6 +1347,25 @@ static void remove_trip_attrs(struct thermal_zone_device *tz) kfree(tz->trip_hyst_attrs); } +static int thermal_zone_create_device_groups(struct thermal_zone_device *tz) +{ + const struct attribute_group **groups; + int i, size; + + size = ARRAY_SIZE(thermal_zone_attribute_groups) + 1; + /* This also takes care of API requirement to be NULL terminated */ + groups = kcalloc(size, sizeof(*groups), GFP_KERNEL); + if (!groups) + return -ENOMEM; + + for (i = 0; i < size - 1; i++) + groups[i] = thermal_zone_attribute_groups[i]; + + tz->device.groups = groups; + + return 0; +} + /* sys I/F for cooling device */ #define to_cooling_device(_dev) \ container_of(_dev, struct thermal_cooling_device, device) @@ -1982,7 +2001,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, tz->polling_delay = polling_delay; /* Add nodes that are always present via .groups */ - tz->device.groups = thermal_zone_attribute_groups; + thermal_zone_create_device_groups(tz); /* A new thermal zone needs to be updated anyway. */ atomic_set(&tz->need_update, 1); @@ -2111,7 +2130,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) idr_destroy(&tz->idr); mutex_destroy(&tz->lock); device_unregister(&tz->device); - return; + kfree(tz->device.groups); } EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);