[PATCH] PM / devfreq: devm_kzalloc to have dev pointer more precisely
From: MyungJoo Ham <myungjoo.ham@samsung.com>
Date: 2016-05-16 02:45:26
Subsystem:
device frequency (devfreq), the rest · Maintainers:
MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Linus Torvalds
devm_kzalloc of devfreq's statistics data structure has been using its parent device as the dev allocated for. If a device's devfreq is disabled in run-time, such allocated memory won't be freed. Desginating more precisely with the devfreq device pointer fixes the issue. Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> --- drivers/devfreq/devfreq.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 984c5e9..31faf85 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c@@ -524,14 +524,6 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_lock(&devfreq->lock); } - devfreq->trans_table = devm_kzalloc(dev, sizeof(unsigned int) * - devfreq->profile->max_state * - devfreq->profile->max_state, - GFP_KERNEL); - devfreq->time_in_state = devm_kzalloc(dev, sizeof(unsigned long) * - devfreq->profile->max_state, - GFP_KERNEL); - devfreq->last_stat_updated = jiffies; dev_set_name(&devfreq->dev, "%s", dev_name(dev)); err = device_register(&devfreq->dev);
@@ -541,6 +533,15 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_out; } + devfreq->trans_table = devm_kzalloc(&devfreq->dev, sizeof(unsigned int) * + devfreq->profile->max_state * + devfreq->profile->max_state, + GFP_KERNEL); + devfreq->time_in_state = devm_kzalloc(&devfreq->dev, sizeof(unsigned long) * + devfreq->profile->max_state, + GFP_KERNEL); + devfreq->last_stat_updated = jiffies; + mutex_unlock(&devfreq->lock); mutex_lock(&devfreq_list_lock);
@@ -967,6 +968,12 @@ unlock: return ret; } +static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq); +} + static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) {
--
1.9.1