1919
2020static size_t max_chunkid (struct z_heap * h )
2121{
22- return h -> len - min_chunk_size (h );
22+ return h -> end_chunk - min_chunk_size (h );
2323}
2424
2525#define VALIDATE (cond ) do { if (!(cond)) { return false; } } while (0)
@@ -28,14 +28,14 @@ static bool in_bounds(struct z_heap *h, chunkid_t c)
2828{
2929 VALIDATE (c >= right_chunk (h , 0 ));
3030 VALIDATE (c <= max_chunkid (h ));
31- VALIDATE (chunk_size (h , c ) < h -> len );
31+ VALIDATE (chunk_size (h , c ) < h -> end_chunk );
3232 return true;
3333}
3434
3535static bool valid_chunk (struct z_heap * h , chunkid_t c )
3636{
3737 VALIDATE (chunk_size (h , c ) > 0 );
38- VALIDATE (c + chunk_size (h , c ) <= h -> len );
38+ VALIDATE (c + chunk_size (h , c ) <= h -> end_chunk );
3939 VALIDATE (in_bounds (h , c ));
4040 VALIDATE (right_chunk (h , left_chunk (h , c )) == c );
4141 VALIDATE (left_chunk (h , right_chunk (h , c )) == c );
@@ -85,15 +85,15 @@ bool sys_heap_validate(struct sys_heap *heap)
8585 return false;
8686 }
8787 }
88- if (c != h -> len ) {
88+ if (c != h -> end_chunk ) {
8989 return false; /* Should have exactly consumed the buffer */
9090 }
9191
9292 /* Check the free lists: entry count should match, empty bit
9393 * should be correct, and all chunk entries should point into
9494 * valid unused chunks. Mark those chunks USED, temporarily.
9595 */
96- for (int b = 0 ; b <= bucket_idx (h , h -> len ); b ++ ) {
96+ for (int b = 0 ; b <= bucket_idx (h , h -> end_chunk ); b ++ ) {
9797 chunkid_t c0 = h -> buckets [b ].next ;
9898 uint32_t n = 0 ;
9999
@@ -137,15 +137,15 @@ bool sys_heap_validate(struct sys_heap *heap)
137137
138138 set_chunk_used (h , c , solo_free_header (h , c ));
139139 }
140- if (c != h -> len ) {
140+ if (c != h -> end_chunk ) {
141141 return false; /* Should have exactly consumed the buffer */
142142 }
143143
144144 /* Go through the free lists again checking that the linear
145145 * pass caught all the blocks and that they now show UNUSED.
146146 * Mark them USED.
147147 */
148- for (int b = 0 ; b <= bucket_idx (h , h -> len ); b ++ ) {
148+ for (int b = 0 ; b <= bucket_idx (h , h -> end_chunk ); b ++ ) {
149149 chunkid_t c0 = h -> buckets [b ].next ;
150150 int n = 0 ;
151151
@@ -318,11 +318,11 @@ void sys_heap_stress(void *(*alloc)(void *arg, size_t bytes),
318318 */
319319void heap_print_info (struct z_heap * h , bool dump_chunks )
320320{
321- int i , nb_buckets = bucket_idx (h , h -> len ) + 1 ;
321+ int i , nb_buckets = bucket_idx (h , h -> end_chunk ) + 1 ;
322322 size_t free_bytes , allocated_bytes , total , overhead ;
323323
324324 printk ("Heap at %p contains %d units in %d buckets\n\n" ,
325- chunk_buf (h ), h -> len , nb_buckets );
325+ chunk_buf (h ), h -> end_chunk , nb_buckets );
326326
327327 printk (" bucket# min units total largest largest\n"
328328 " threshold chunks (units) (bytes)\n"
@@ -352,7 +352,7 @@ void heap_print_info(struct z_heap *h, bool dump_chunks)
352352 }
353353 free_bytes = allocated_bytes = 0 ;
354354 for (chunkid_t c = 0 ; ; c = right_chunk (h , c )) {
355- if (c == 0 || c == h -> len ) {
355+ if (c == 0 || c == h -> end_chunk ) {
356356 /* those are always allocated for internal purposes */
357357 } else if (chunk_used (h , c )) {
358358 allocated_bytes += chunk_size (h , c ) * CHUNK_UNIT
@@ -371,16 +371,13 @@ void heap_print_info(struct z_heap *h, bool dump_chunks)
371371 left_chunk (h , c ),
372372 right_chunk (h , c ));
373373 }
374- if (c == h -> len ) {
374+ if (c == h -> end_chunk ) {
375375 break ;
376376 }
377377 }
378378
379- /*
380- * The final chunk at h->len is just a header serving as a end
381- * marker. It is part of the overhead.
382- */
383- total = h -> len * CHUNK_UNIT + chunk_header_bytes (h );
379+ /* The end marker chunk has a header. It is part of the overhead. */
380+ total = h -> end_chunk * CHUNK_UNIT + chunk_header_bytes (h );
384381 overhead = total - free_bytes - allocated_bytes ;
385382 printk ("\n%zd free bytes, %zd allocated bytes, overhead = %zd bytes (%zd.%zd%%)\n" ,
386383 free_bytes , allocated_bytes , overhead ,
0 commit comments