diff options
author | Matt Fleming <matt.fleming@intel.com> | 2012-09-11 17:22:14 +0100 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2012-09-11 18:20:34 +0100 |
commit | 9e657f72da9f5bfb66e534ce5ddeda4d5d9c936d (patch) | |
tree | c765d103243f8e86ff314d8c001ad61bc35bb7b8 | |
parent | 97402a0a16399ab0c396583cf1c7d16c05ac6753 (diff) | |
download | syslinux-9e657f72da9f5bfb66e534ce5ddeda4d5d9c936d.tar.gz syslinux-9e657f72da9f5bfb66e534ce5ddeda4d5d9c936d.tar.xz syslinux-9e657f72da9f5bfb66e534ce5ddeda4d5d9c936d.zip |
efi: We don't need two memory_map() functions
There are two functions for getting the EFI memory map, each with a
different sets of semantics. get_memory_map() returns the number of
entries in the map in it's first parameter, whereas memory_map()
returns the size of the memory map. The implementation of memory_map()
is bogus as it mixes up the semantics by calling get_memory_map().
The two functions do pretty much the same thing anyway so delete the
buggy one.
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
-rw-r--r-- | efi/main.c | 59 |
1 files changed, 8 insertions, 51 deletions
@@ -639,49 +639,6 @@ static EFI_STATUS setup_default_timer(EFI_EVENT ev) } /** - * memory_map - Allocate and fill out an array of memory descriptors - * @map_buf: buffer containing the memory map - * @map_size: size of the buffer containing the memory map - * @map_key: key for the current memory map - * @desc_size: size of the desc - * @desc_version: memory descriptor version - * - * On success, @map_size contains the size of the memory map pointed - * to by @map_buf and @map_key, @desc_size and @desc_version are - * updated. - */ -EFI_STATUS -memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size, - UINTN *map_key, UINTN *desc_size, UINT32 *desc_version) -{ - EFI_STATUS err = EFI_SUCCESS; - - *map_size = sizeof(**map_buf) * 31; - - /* - * Because we're about to allocate memory, we may - * potentially create a new memory descriptor, thereby - * increasing the size of the memory map. So increase - * the buffer size by the size of one memory - * descriptor, just in case. - */ - *map_size += sizeof(**map_buf); - - err = allocate_pool(EfiLoaderData, *map_size, - (void **)map_buf); - if (err == EFI_SUCCESS) { - *map_buf = get_memory_map(map_size, map_key, desc_size, desc_version); - if (*map_buf == (EFI_MEMORY_DESCRIPTOR *)NULL) { - Print(L"Failed to get memory map"); - err = EFI_OUT_OF_RESOURCES; - } - } else { - Print(L"Failed to allocate pool for memory map"); - } - - return err; -} -/** * emalloc - Allocate memory with a strict alignment requirement * @size: size in bytes of the requested allocation * @align: the required alignment of the allocation @@ -691,22 +648,22 @@ memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size, */ EFI_STATUS emalloc(UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS *addr) { - UINTN map_size, map_key, desc_size; + UINTN nr_entries, map_key, desc_size; EFI_MEMORY_DESCRIPTOR *map_buf; - UINTN d, map_end; + UINTN d; UINT32 desc_version; EFI_STATUS err; UINTN nr_pages = EFI_SIZE_TO_PAGES(size); + int i; - err = memory_map(&map_buf, &map_size, &map_key, - &desc_size, &desc_version); - if (err != EFI_SUCCESS) + map_buf = get_memory_map(&nr_entries, &map_key, + &desc_size, &desc_version); + if (!map_buf) goto fail; d = (UINTN)map_buf; - map_end = (UINTN)map_buf + map_size; - for (; d < map_end; d += desc_size) { + for (i = 0; i < nr_entries; i++, d += desc_size) { EFI_MEMORY_DESCRIPTOR *desc; EFI_PHYSICAL_ADDRESS start, end, aligned; @@ -740,7 +697,7 @@ EFI_STATUS emalloc(UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS *addr) } } - if (d == map_end) + if (i == nr_entries) err = EFI_OUT_OF_RESOURCES; free_pool(map_buf); |