EFI loader: remove redundant code
PATCH v2 1/1 EFI loader: remove redundant code
*e820ext is always NULL in 'alloc_e820ext()' (see the code of 'exit_boot()'). Without loss of generality we can replace freeing with returning EFI_INVALID_PARAMETER. So if the caller would ever incorrectly pass non-NULL *e820ext, he will obtain a returned error code.
--- arch/x86/boot/compressed/eboot.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/boot/compressed/eboot.c +2 -5
@@ -956,11 +956,8 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, size =sizeof (struct setup_data ) +sizeof (struct e820entry ) * nr_desc; -if (*e820ext) { -efi_call_early (free_pool, *e820ext); - *e820ext =NULL ; - *e820ext_size =0 ; - } +if (*e820ext) +return EFI_INVALID_PARAMETER ; status =efi_call_early (allocate_pool,EFI_LOADER_DATA , size, (void **)e820ext);
Signature · 1 line
2.10.2
Hello Eugene,
Quoted 5 lines · Eugene Korenevsky
*e820ext is always NULL in '
alloc_e820ext()' (see the code of 'exit_boot()'). Without loss of generality we can replace freeing with returningEFI_INVALID_PARAMETER. So if the caller would ever incorrectly pass non-NULL *e820ext, he will obtain a returned error code.
What exactly are you trying to fix here? Adding new artificial failure modes is hardly worth it when all you are doing is cleaning up code that by itself is correct to begin with, but is simply never called.
Quoted 25 lines
--- arch/x86/boot/compressed/eboot.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)arch/x86/boot/compressed/eboot.c +2
-6@@ -956,11 +956,8 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, size =sizeof (struct setup_data ) +sizeof (struct e820entry ) * nr_desc; -if (*e820ext) { -efi_call_early (free_pool, *e820ext); - *e820ext =NULL ; - *e820ext_size =0 ; - } +if (*e820ext) +return EFI_INVALID_PARAMETER ; status =efi_call_early (allocate_pool,EFI_LOADER_DATA , size, (void **)e820ext); --2.10.2
Quoted 9 lines
Quoted 5 lines
*e820ext is always NULL in '
alloc_e820ext()' (see the code of 'exit_boot()'). Without loss of generality we can replace freeing with returningEFI_INVALID_PARAMETER. So if the caller would ever incorrectly pass non-NULL *e820ext, he will obtain a returned error code.What exactly are you trying to fix here? Adding new artificial failure modes is hardly worth it when all you are doing is cleaning up code that by itself is correct to begin with, but is simply never called.
This code (free_pool, assignments) is dead whether it is correct or not. So it is to be removed.
The check gives some assurance that memory is not leaked if the calling code is changed.
Quoted 15 lines
Quoted 15 lines
arch/x86/boot/compressed/eboot.c +2
-6@@ -956,11 +956,8 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, size =sizeof (struct setup_data ) +sizeof (struct e820entry ) * nr_desc; -if (*e820ext) { -efi_call_early (free_pool, *e820ext); - *e820ext =NULL ; - *e820ext_size =0 ; - } +if (*e820ext) +return EFI_INVALID_PARAMETER ; status =efi_call_early (allocate_pool,EFI_LOADER_DATA , size, (void **)e820ext); --
Signature · 1 line
Eugene
Quoted 6 lines · Eugene Korenevsky
Quoted 6 lines
Quoted 5 lines
*e820ext is always NULL in '
alloc_e820ext()' (see the code of 'exit_boot()'). Without loss of generality we can replace freeing with returningEFI_INVALID_PARAMETER. So if the caller would ever incorrectly pass non-NULL *e820ext, he will obtain a returned error code.
Quoted 9 lines
Quoted 3 lines
What exactly are you trying to fix here? Adding new artificial failure modes is hardly worth it when all you are doing is cleaning up code that by itself is correct to begin with, but is simply never called.
This code (
free_pool, assignments) is dead whether it is correct or not. So it is to be removed.
The check gives some assurance that memory is not leaked if the calling code is changed.
No, it doesn't. This code executes in the context of the UEFI firmware, which is riddled with bugs on older x86 platforms (as well as non newer non-x86 platforms). By returning an error at runtime, you may be breaking the boot for someone who wil have *no* idea whatsoever what is going on.
If you want to clean this up in a way that prevents future issues, please use something like BUILD_BUG()