aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Franz <roy.franz@linaro.org>2013-09-22 18:45:30 -0400
committerMatt Fleming <matt.fleming@intel.com>2013-09-25 07:34:36 -0400
commit38dd9c02c3f2ed461165db22b93fae7f3ddde9ac (patch)
tree8e1d0ea4c9af90e91a58ef24e52f4c7d08a95f40
parent40e4530a00b7d52332fe9a1361388fda8e5260da (diff)
efi: Enforce minimum alignment of 1 page on allocations.
The efi_high_alloc() and efi_low_alloc() functions use the EFI_ALLOCATE_ADDRESS option to the EFI function allocate_pages(), which requires a minimum of page alignment, and rejects all other requests. The existing code could fail to allocate depending on allocation size, as although repeated allocation attempts were made, none were guaranteed to be page aligned. Signed-off-by: Roy Franz <roy.franz@linaro.org> Acked-by: Mark Salter <msalter@redhat.com> Reviewed-by: Grant Likely <grant.likely@linaro.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
-rw-r--r--drivers/firmware/efi/efi-stub-helper.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index 2f528fb541f9..a25675833598 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -101,6 +101,14 @@ static efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
101 if (status != EFI_SUCCESS) 101 if (status != EFI_SUCCESS)
102 goto fail; 102 goto fail;
103 103
104 /*
105 * Enforce minimum alignment that EFI requires when requesting
106 * a specific address. We are doing page-based allocations,
107 * so we must be aligned to a page.
108 */
109 if (align < EFI_PAGE_SIZE)
110 align = EFI_PAGE_SIZE;
111
104 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 112 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
105again: 113again:
106 for (i = 0; i < map_size / desc_size; i++) { 114 for (i = 0; i < map_size / desc_size; i++) {
@@ -179,6 +187,14 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
179 if (status != EFI_SUCCESS) 187 if (status != EFI_SUCCESS)
180 goto fail; 188 goto fail;
181 189
190 /*
191 * Enforce minimum alignment that EFI requires when requesting
192 * a specific address. We are doing page-based allocations,
193 * so we must be aligned to a page.
194 */
195 if (align < EFI_PAGE_SIZE)
196 align = EFI_PAGE_SIZE;
197
182 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 198 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
183 for (i = 0; i < map_size / desc_size; i++) { 199 for (i = 0; i < map_size / desc_size; i++) {
184 efi_memory_desc_t *desc; 200 efi_memory_desc_t *desc;