Skip to content

Commit 8552d68

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM: EM: Split the allocation and initialization of the EM table
Split the process of allocation and data initialization for the EM table. The upcoming changes for modifiable EM will use it. This change is not expected to alter the general functionality. Reviewed-by: Dietmar Eggemann <[email protected]> Tested-by: Dietmar Eggemann <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8188672 commit 8552d68

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

kernel/power/energy_model.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,26 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table,
142142
return 0;
143143
}
144144

145+
static int em_allocate_perf_table(struct em_perf_domain *pd,
146+
int nr_states)
147+
{
148+
pd->table = kcalloc(nr_states, sizeof(struct em_perf_state),
149+
GFP_KERNEL);
150+
if (!pd->table)
151+
return -ENOMEM;
152+
153+
return 0;
154+
}
155+
145156
static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
146-
int nr_states, struct em_data_callback *cb,
157+
struct em_perf_state *table,
158+
struct em_data_callback *cb,
147159
unsigned long flags)
148160
{
149161
unsigned long power, freq, prev_freq = 0;
150-
struct em_perf_state *table;
162+
int nr_states = pd->nr_perf_states;
151163
int i, ret;
152164

153-
table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL);
154-
if (!table)
155-
return -ENOMEM;
156-
157165
/* Build the list of performance states for this performance domain */
158166
for (i = 0, freq = 0; i < nr_states; i++, freq++) {
159167
/*
@@ -165,7 +173,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
165173
if (ret) {
166174
dev_err(dev, "EM: invalid perf. state: %d\n",
167175
ret);
168-
goto free_ps_table;
176+
return -EINVAL;
169177
}
170178

171179
/*
@@ -175,7 +183,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
175183
if (freq <= prev_freq) {
176184
dev_err(dev, "EM: non-increasing freq: %lu\n",
177185
freq);
178-
goto free_ps_table;
186+
return -EINVAL;
179187
}
180188

181189
/*
@@ -185,7 +193,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
185193
if (!power || power > EM_MAX_POWER) {
186194
dev_err(dev, "EM: invalid power: %lu\n",
187195
power);
188-
goto free_ps_table;
196+
return -EINVAL;
189197
}
190198

191199
table[i].power = power;
@@ -194,16 +202,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
194202

195203
ret = em_compute_costs(dev, table, cb, nr_states, flags);
196204
if (ret)
197-
goto free_ps_table;
198-
199-
pd->table = table;
200-
pd->nr_perf_states = nr_states;
205+
return -EINVAL;
201206

202207
return 0;
203-
204-
free_ps_table:
205-
kfree(table);
206-
return -EINVAL;
207208
}
208209

209210
static int em_create_pd(struct device *dev, int nr_states,
@@ -234,11 +235,15 @@ static int em_create_pd(struct device *dev, int nr_states,
234235
return -ENOMEM;
235236
}
236237

237-
ret = em_create_perf_table(dev, pd, nr_states, cb, flags);
238-
if (ret) {
239-
kfree(pd);
240-
return ret;
241-
}
238+
pd->nr_perf_states = nr_states;
239+
240+
ret = em_allocate_perf_table(pd, nr_states);
241+
if (ret)
242+
goto free_pd;
243+
244+
ret = em_create_perf_table(dev, pd, pd->table, cb, flags);
245+
if (ret)
246+
goto free_pd_table;
242247

243248
if (_is_cpu_device(dev))
244249
for_each_cpu(cpu, cpus) {
@@ -249,6 +254,12 @@ static int em_create_pd(struct device *dev, int nr_states,
249254
dev->em_pd = pd;
250255

251256
return 0;
257+
258+
free_pd_table:
259+
kfree(pd->table);
260+
free_pd:
261+
kfree(pd);
262+
return -EINVAL;
252263
}
253264

254265
static void

0 commit comments

Comments
 (0)