@@ -135,6 +135,10 @@ void cpuinfo_x86_freebsd_init(void) {
135135 if (x86_processor .cache .l1i .size != 0 || x86_processor .cache .l1d .size != 0 ) {
136136 /* Assume that threads on the same core share L1 */
137137 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+ }
138142 cpuinfo_log_warning (
139143 "freebsd kernel did not report number of "
140144 "threads sharing L1 cache; assume %" PRIu32 ,
@@ -154,6 +158,10 @@ void cpuinfo_x86_freebsd_init(void) {
154158 * the same package share L2 */
155159 threads_per_l2 = freebsd_topology .threads / freebsd_topology .packages ;
156160 }
161+ if (threads_per_l2 == 0 ) {
162+ cpuinfo_log_error ("failed to detect threads_per_l1" );
163+ goto cleanup ;
164+ }
157165 cpuinfo_log_warning (
158166 "freebsd kernel did not report number of "
159167 "threads sharing L2 cache; assume %" PRIu32 ,
@@ -170,6 +178,10 @@ void cpuinfo_x86_freebsd_init(void) {
170178 * may be L4 cache as well)
171179 */
172180 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+ }
173185 cpuinfo_log_warning (
174186 "freebsd kernel did not report number of "
175187 "threads sharing L3 cache; assume %" PRIu32 ,
@@ -187,6 +199,10 @@ void cpuinfo_x86_freebsd_init(void) {
187199 * shared L4 (like on IBM POWER8).
188200 */
189201 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+ }
190206 cpuinfo_log_warning (
191207 "freebsd kernel did not report number of "
192208 "threads sharing L4 cache; assume %" PRIu32 ,
@@ -203,7 +219,7 @@ void cpuinfo_x86_freebsd_init(void) {
203219 "%" PRIu32 " L1I caches" ,
204220 l1_count * sizeof (struct cpuinfo_cache ),
205221 l1_count );
206- return ;
222+ goto cleanup ;
207223 }
208224 for (uint32_t c = 0 ; c < l1_count ; c ++ ) {
209225 l1i [c ] = (struct cpuinfo_cache ){
@@ -230,7 +246,7 @@ void cpuinfo_x86_freebsd_init(void) {
230246 "%" PRIu32 " L1D caches" ,
231247 l1_count * sizeof (struct cpuinfo_cache ),
232248 l1_count );
233- return ;
249+ goto cleanup ;
234250 }
235251 for (uint32_t c = 0 ; c < l1_count ; c ++ ) {
236252 l1d [c ] = (struct cpuinfo_cache ){
@@ -257,7 +273,7 @@ void cpuinfo_x86_freebsd_init(void) {
257273 "%" PRIu32 " L2 caches" ,
258274 l2_count * sizeof (struct cpuinfo_cache ),
259275 l2_count );
260- return ;
276+ goto cleanup ;
261277 }
262278 for (uint32_t c = 0 ; c < l2_count ; c ++ ) {
263279 l2 [c ] = (struct cpuinfo_cache ){
@@ -284,7 +300,7 @@ void cpuinfo_x86_freebsd_init(void) {
284300 "%" PRIu32 " L3 caches" ,
285301 l3_count * sizeof (struct cpuinfo_cache ),
286302 l3_count );
287- return ;
303+ goto cleanup ;
288304 }
289305 for (uint32_t c = 0 ; c < l3_count ; c ++ ) {
290306 l3 [c ] = (struct cpuinfo_cache ){
@@ -311,7 +327,7 @@ void cpuinfo_x86_freebsd_init(void) {
311327 "%" PRIu32 " L4 caches" ,
312328 l4_count * sizeof (struct cpuinfo_cache ),
313329 l4_count );
314- return ;
330+ goto cleanup ;
315331 }
316332 for (uint32_t c = 0 ; c < l4_count ; c ++ ) {
317333 l4 [c ] = (struct cpuinfo_cache ){
0 commit comments