Author: mcayland Date: Sun Mar 30 19:31:01 2014 New Revision: 1281 URL: http://tracker.coreboot.org/trac/openbios/changeset/1281
Log: OFMEM: improve remove_range_() function algorithm
Rework the algorithm used in remove_range_() in order to make it similar to the algorithm used in unmap_pages(). This has several benefits: in particular the unmap_pages()/remove_range_() functions now have the same behaviour, the code is noticeably simpler, and it also correctly handles the case where the start address of the range to be removed doesn't match the range exactly (such as occurs when attempting to boot NextStep under SPARC32).
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
Modified: trunk/openbios-devel/libopenbios/ofmem_common.c
Modified: trunk/openbios-devel/libopenbios/ofmem_common.c ============================================================================== --- trunk/openbios-devel/libopenbios/ofmem_common.c Sun Mar 9 21:51:13 2014 (r1280) +++ trunk/openbios-devel/libopenbios/ofmem_common.c Sun Mar 30 19:31:01 2014 (r1281) @@ -885,23 +885,18 @@
static void remove_range_( phys_addr_t ea, ucell size, range_t **r ) { - range_t *cr; + range_t **t, *u;
- /* Handle special case if we're removing the first entry */ - if ((**r).start >= ea) { - cr = *r; - *r = (**r).next; - free(cr); - - return; - } - - for( ; *r && ((**r).next)->start < ea; r=&(**r).next ) { + for (t = r; *t; t = &(**t).next) { + if (ea >= (**t).start && ea + size <= (**t).start + (**t).size) { + OFMEM_TRACE("remove_range_ freeing range with addr=" FMT_plx + " size=" FMT_ucellx "\n", (**t).start, (**t).size); + u = *t; + *t = (**t).next; + free(u); + break; + } } - - cr = (**r).next; - (**r).next = cr->next; - free(cr); }
static int remove_range( phys_addr_t ea, ucell size, range_t **r )