diff mbox series

[6/7] devfreq: move transition statistics allocations to set_freq_stats()

Message ID 20191113091336.5218-7-k.konieczny@samsung.com (mailing list archive)
State Not Applicable, archived
Headers show
Series devfreq: improve devfreq statistics counting | expand

Commit Message

Kamil Konieczny Nov. 13, 2019, 9:13 a.m. UTC
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(-)
diff mbox series

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 70533b787744..d79412b0de59 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -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: