@@ -142,18 +142,26 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table,
142
142
return 0 ;
143
143
}
144
144
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
+
145
156
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 ,
147
159
unsigned long flags )
148
160
{
149
161
unsigned long power , freq , prev_freq = 0 ;
150
- struct em_perf_state * table ;
162
+ int nr_states = pd -> nr_perf_states ;
151
163
int i , ret ;
152
164
153
- table = kcalloc (nr_states , sizeof (* table ), GFP_KERNEL );
154
- if (!table )
155
- return - ENOMEM ;
156
-
157
165
/* Build the list of performance states for this performance domain */
158
166
for (i = 0 , freq = 0 ; i < nr_states ; i ++ , freq ++ ) {
159
167
/*
@@ -165,7 +173,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
165
173
if (ret ) {
166
174
dev_err (dev , "EM: invalid perf. state: %d\n" ,
167
175
ret );
168
- goto free_ps_table ;
176
+ return - EINVAL ;
169
177
}
170
178
171
179
/*
@@ -175,7 +183,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
175
183
if (freq <= prev_freq ) {
176
184
dev_err (dev , "EM: non-increasing freq: %lu\n" ,
177
185
freq );
178
- goto free_ps_table ;
186
+ return - EINVAL ;
179
187
}
180
188
181
189
/*
@@ -185,7 +193,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
185
193
if (!power || power > EM_MAX_POWER ) {
186
194
dev_err (dev , "EM: invalid power: %lu\n" ,
187
195
power );
188
- goto free_ps_table ;
196
+ return - EINVAL ;
189
197
}
190
198
191
199
table [i ].power = power ;
@@ -194,16 +202,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
194
202
195
203
ret = em_compute_costs (dev , table , cb , nr_states , flags );
196
204
if (ret )
197
- goto free_ps_table ;
198
-
199
- pd -> table = table ;
200
- pd -> nr_perf_states = nr_states ;
205
+ return - EINVAL ;
201
206
202
207
return 0 ;
203
-
204
- free_ps_table :
205
- kfree (table );
206
- return - EINVAL ;
207
208
}
208
209
209
210
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,
234
235
return - ENOMEM ;
235
236
}
236
237
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 ;
242
247
243
248
if (_is_cpu_device (dev ))
244
249
for_each_cpu (cpu , cpus ) {
@@ -249,6 +254,12 @@ static int em_create_pd(struct device *dev, int nr_states,
249
254
dev -> em_pd = pd ;
250
255
251
256
return 0 ;
257
+
258
+ free_pd_table :
259
+ kfree (pd -> table );
260
+ free_pd :
261
+ kfree (pd );
262
+ return - EINVAL ;
252
263
}
253
264
254
265
static void
0 commit comments