@@ -135,6 +135,10 @@ void cpuinfo_x86_freebsd_init(void) {
135
135
if (x86_processor .cache .l1i .size != 0 || x86_processor .cache .l1d .size != 0 ) {
136
136
/* Assume that threads on the same core share L1 */
137
137
threads_per_l1 = freebsd_topology .threads / freebsd_topology .cores ;
138
+ if (threads_per_l1 == 0 ) {
139
+ cpuinfo_log_error ("failed to detect threads_per_l1" );
140
+ goto cleanup ;
141
+ }
138
142
cpuinfo_log_warning (
139
143
"freebsd kernel did not report number of "
140
144
"threads sharing L1 cache; assume %" PRIu32 ,
@@ -154,6 +158,10 @@ void cpuinfo_x86_freebsd_init(void) {
154
158
* the same package share L2 */
155
159
threads_per_l2 = freebsd_topology .threads / freebsd_topology .packages ;
156
160
}
161
+ if (threads_per_l2 == 0 ) {
162
+ cpuinfo_log_error ("failed to detect threads_per_l1" );
163
+ goto cleanup ;
164
+ }
157
165
cpuinfo_log_warning (
158
166
"freebsd kernel did not report number of "
159
167
"threads sharing L2 cache; assume %" PRIu32 ,
@@ -170,6 +178,10 @@ void cpuinfo_x86_freebsd_init(void) {
170
178
* may be L4 cache as well)
171
179
*/
172
180
threads_per_l3 = freebsd_topology .threads / freebsd_topology .packages ;
181
+ if (threads_per_l3 == 0 ) {
182
+ cpuinfo_log_error ("failed to detect threads_per_l3" );
183
+ goto cleanup ;
184
+ }
173
185
cpuinfo_log_warning (
174
186
"freebsd kernel did not report number of "
175
187
"threads sharing L3 cache; assume %" PRIu32 ,
@@ -187,6 +199,10 @@ void cpuinfo_x86_freebsd_init(void) {
187
199
* shared L4 (like on IBM POWER8).
188
200
*/
189
201
threads_per_l4 = freebsd_topology .threads ;
202
+ if (threads_per_l4 == 0 ) {
203
+ cpuinfo_log_error ("failed to detect threads_per_l4" );
204
+ goto cleanup ;
205
+ }
190
206
cpuinfo_log_warning (
191
207
"freebsd kernel did not report number of "
192
208
"threads sharing L4 cache; assume %" PRIu32 ,
@@ -203,7 +219,7 @@ void cpuinfo_x86_freebsd_init(void) {
203
219
"%" PRIu32 " L1I caches" ,
204
220
l1_count * sizeof (struct cpuinfo_cache ),
205
221
l1_count );
206
- return ;
222
+ goto cleanup ;
207
223
}
208
224
for (uint32_t c = 0 ; c < l1_count ; c ++ ) {
209
225
l1i [c ] = (struct cpuinfo_cache ){
@@ -230,7 +246,7 @@ void cpuinfo_x86_freebsd_init(void) {
230
246
"%" PRIu32 " L1D caches" ,
231
247
l1_count * sizeof (struct cpuinfo_cache ),
232
248
l1_count );
233
- return ;
249
+ goto cleanup ;
234
250
}
235
251
for (uint32_t c = 0 ; c < l1_count ; c ++ ) {
236
252
l1d [c ] = (struct cpuinfo_cache ){
@@ -257,7 +273,7 @@ void cpuinfo_x86_freebsd_init(void) {
257
273
"%" PRIu32 " L2 caches" ,
258
274
l2_count * sizeof (struct cpuinfo_cache ),
259
275
l2_count );
260
- return ;
276
+ goto cleanup ;
261
277
}
262
278
for (uint32_t c = 0 ; c < l2_count ; c ++ ) {
263
279
l2 [c ] = (struct cpuinfo_cache ){
@@ -284,7 +300,7 @@ void cpuinfo_x86_freebsd_init(void) {
284
300
"%" PRIu32 " L3 caches" ,
285
301
l3_count * sizeof (struct cpuinfo_cache ),
286
302
l3_count );
287
- return ;
303
+ goto cleanup ;
288
304
}
289
305
for (uint32_t c = 0 ; c < l3_count ; c ++ ) {
290
306
l3 [c ] = (struct cpuinfo_cache ){
@@ -311,7 +327,7 @@ void cpuinfo_x86_freebsd_init(void) {
311
327
"%" PRIu32 " L4 caches" ,
312
328
l4_count * sizeof (struct cpuinfo_cache ),
313
329
l4_count );
314
- return ;
330
+ goto cleanup ;
315
331
}
316
332
for (uint32_t c = 0 ; c < l4_count ; c ++ ) {
317
333
l4 [c ] = (struct cpuinfo_cache ){
0 commit comments