From patchwork Wed May 4 06:02:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9010531 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 BDE24BF29F for ; Wed, 4 May 2016 06:08:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC9ED202EC for ; Wed, 4 May 2016 06:08:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 108932027D for ; Wed, 4 May 2016 06:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757172AbcEDGDK (ORCPT ); Wed, 4 May 2016 02:03:10 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:36405 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757152AbcEDGDI (ORCPT ); Wed, 4 May 2016 02:03:08 -0400 Received: by mail-pf0-f174.google.com with SMTP id c189so21826197pfb.3; Tue, 03 May 2016 23:03:07 -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=DZOZ8OYF6VTLdBeKkjf9CLlUE662HBbfucKMbRm4F9U=; b=Y74ulIYOCiUoyvG6GpFiNOPDPDBuV/xUYE/Kurq1+YHuehD8hiEOBD5MogC1dq2En6 MFeP1ou2GVjuuPbpDP17gUepl7tNFEXskeFE6MI88bFEzo5KXpo60hPk3CQCOKH9uetN 2MR9UAjnIKBngzYeeVHTFIBGJJjk/ofjk0cG+eosVeNRmmAVB+JoC69986slWa/wvM+B w099qHgRHv943SD2ALHlCWwrrKtoUQlPF4xl8N6uyXMDpF6dOWt+4J3Xw1Avbpvg5EXD O6CgBdBO1W8Qojc1HKR+SyhddQYeVeQR2tspXBqOGAIPutvhLAR5SDl0DjHYFbKGVFv5 jm2A== 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=DZOZ8OYF6VTLdBeKkjf9CLlUE662HBbfucKMbRm4F9U=; b=gwytQGc/k0BJQOxTcsmYp/2myBp19sRdR6EP909cVcOoLtsVqqhhlv9ShkB3n/K59n cIE++YOUU5M7lngPJ/djC2b1NCXSGfKhPk8lnewX5eLzoyv9PKbZrSjtqOCUn86MFaUY IiXbGy7bWlopQ3o/KY1TiVvaMpkDO3tNLaKuumMIRVb4BfZTXb/xzSBOKIaDVhsiWBLn yD3rOYIDlxVnYzriPV0xJC/ACory9cyCzz5WWISGvteldpF03fVthlOICL6E9gzZaPrE aLGvwVhUYNp7dpnr3EDKz1AZ+pR3X1W/dFY1rJTzslbhFlCp2iXcnvVsWGVImRsDkIr7 fxIA== X-Gm-Message-State: AOPr4FXoatjR1T4DM6GycYws44y0CWNZXt0i/AwgFibaM4jDUNn1zg15T+g5DPykkth7Vg== X-Received: by 10.98.100.71 with SMTP id y68mr9654514pfb.84.1462341787269; Tue, 03 May 2016 23:03:07 -0700 (PDT) Received: from localhost ([2601:647:4203:c8e0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id 5sm2636894pfn.46.2016.05.03.23.03.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 May 2016 23:03:06 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 10/31] thermal: core: create tz->device.groups dynamically Date: Tue, 3 May 2016 23:02:24 -0700 Message-Id: <1462341765-13268-11-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 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 b1b2945..13a85d7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1169,7 +1169,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 */ }; /** @@ -1281,6 +1281,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 = kzalloc(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) @@ -1913,7 +1932,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); @@ -2042,7 +2061,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);