@@ -147,7 +147,26 @@ static int set_freq_table(struct devfreq *devfreq)
profile->freq_table[i] = freq;
}
+ profile->trans_table = devm_kzalloc(devfreq->dev.parent,
+ array3_size(sizeof(unsigned int),
+ count, count),
+ GFP_KERNEL);
+ if (!profile->trans_table)
+ goto err_no_mem;
+
+ profile->time_in_state = devm_kcalloc(devfreq->dev.parent, count,
+ sizeof(*profile->time_in_state),
+ GFP_KERNEL);
+ if (!profile->time_in_state)
+ goto err_no_mem;
+
+ profile->last_time = get_jiffies_64();
+ spin_lock_init(&profile->stats_lock);
+
return 0;
+err_no_mem:
+ profile->max_state = 0;
+ return -ENOMEM;
}
/**
@@ -694,30 +713,6 @@ struct devfreq *devfreq_add_device(struct device *dev,
goto err_out;
}
- profile->trans_table = devm_kzalloc(&devfreq->dev,
- array3_size(sizeof(unsigned int),
- profile->max_state,
- profile->max_state),
- GFP_KERNEL);
- if (!profile->trans_table) {
- mutex_unlock(&devfreq->lock);
- err = -ENOMEM;
- goto err_devfreq;
- }
-
- profile->time_in_state = devm_kcalloc(&devfreq->dev,
- profile->max_state,
- sizeof(*profile->time_in_state),
- GFP_KERNEL);
- if (!profile->time_in_state) {
- mutex_unlock(&devfreq->lock);
- err = -ENOMEM;
- goto err_devfreq;
- }
-
- profile->last_time = get_jiffies_64();
- spin_lock_init(&profile->stats_lock);
-
srcu_init_notifier_head(&devfreq->transition_notifier_list);
mutex_unlock(&devfreq->lock);
@@ -749,7 +744,6 @@ struct devfreq *devfreq_add_device(struct device *dev,
err_init:
mutex_unlock(&devfreq_list_lock);
-err_devfreq:
devfreq_remove_device(devfreq);
devfreq = NULL;
err_dev:
All users of [devm_]devfreq_add_device() don't set freq_table nor max_state, and there is only one "struct devfreq_profile" per every "struct devfreq", so move transition memory allocations to function set_freq_stats() and initialize there other statistics fields. Signed-off-by: Kamil Konieczny <k.konieczny@samsung.com> --- drivers/devfreq/devfreq.c | 44 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-)