summaryrefslogtreecommitdiff
path: root/drivers/thermal/thermal_core.c
diff options
context:
space:
mode:
authorEduardo Valentin <edubezval@gmail.com>2016-11-08 08:08:51 +0300
committerZhang Rui <rui.zhang@intel.com>2016-11-23 05:06:12 +0300
commite161aefb9a5fff038054231ffb80abbc2aa42238 (patch)
treefe6ea65a708b74a4ffb2de7030480dbed8784903 /drivers/thermal/thermal_core.c
parent0a9de81907e6dc2adaddedca91ee26a7479b3750 (diff)
downloadlinux-e161aefb9a5fff038054231ffb80abbc2aa42238.tar.xz
thermal: core: create tz->device.groups dynamically
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 <rui.zhang@intel.com> Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin <edubezval@gmail.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Diffstat (limited to 'drivers/thermal/thermal_core.c')
-rw-r--r--drivers/thermal/thermal_core.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index e399ae67b18b..971f033368b2 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);