@@ -615,7 +615,6 @@ void init_heap(struct sof *sof)
615615 struct block_map * current_map ;
616616 int i ;
617617 int j ;
618- int k ;
619618
620619 /* sanity check for malformed images or loader issues */
621620 if (memmap .system [0 ].heap != HEAP_SYSTEM_0_BASE )
@@ -627,20 +626,19 @@ void init_heap(struct sof *sof)
627626 for (i = 0 ; i < PLATFORM_HEAP_BUFFER ; i ++ ) {
628627 heap = & memmap .buffer [i ];
629628
630- for (j = 0 ; j < heap -> blocks ; j ++ ) {
631-
629+ /* init the map[0] */
630+ current_map = & heap -> map [0 ];
631+ current_map -> base = heap -> heap ;
632+ flush_block_map (current_map );
633+
634+ /* map[j]'s base is calculated based on map[j-1] */
635+ for (j = 1 ; j < heap -> blocks ; j ++ ) {
636+ next_map = & heap -> map [j ];
637+ next_map -> base = current_map -> base +
638+ current_map -> block_size *
639+ current_map -> count ;
632640 current_map = & heap -> map [j ];
633- current_map -> base = heap -> heap ;
634641 flush_block_map (current_map );
635-
636- for (k = 1 ; k < heap -> blocks ; k ++ ) {
637- next_map = & heap -> map [k ];
638- next_map -> base = current_map -> base +
639- current_map -> block_size *
640- current_map -> count ;
641- current_map = & heap -> map [k ];
642- flush_block_map (current_map );
643- }
644642 }
645643
646644 dcache_writeback_invalidate_region (heap , sizeof (* heap ));
@@ -650,20 +648,19 @@ void init_heap(struct sof *sof)
650648 for (i = 0 ; i < PLATFORM_HEAP_RUNTIME ; i ++ ) {
651649 heap = & memmap .runtime [i ];
652650
653- for (j = 0 ; j < heap -> blocks ; j ++ ) {
654-
651+ /* init the map[0] */
652+ current_map = & heap -> map [0 ];
653+ current_map -> base = heap -> heap ;
654+ flush_block_map (current_map );
655+
656+ /* map[j]'s base is calculated based on map[j-1] */
657+ for (j = 1 ; j < heap -> blocks ; j ++ ) {
658+ next_map = & heap -> map [j ];
659+ next_map -> base = current_map -> base +
660+ current_map -> block_size *
661+ current_map -> count ;
655662 current_map = & heap -> map [j ];
656- current_map -> base = heap -> heap ;
657663 flush_block_map (current_map );
658-
659- for (k = 1 ; k < heap -> blocks ; k ++ ) {
660- next_map = & heap -> map [k ];
661- next_map -> base = current_map -> base +
662- current_map -> block_size *
663- current_map -> count ;
664- current_map = & heap -> map [k ];
665- flush_block_map (current_map );
666- }
667664 }
668665
669666 dcache_writeback_invalidate_region (heap , sizeof (* heap ));
0 commit comments