[PATCH] efi_loader: initialize 'total' variable

Andrew Goodbody andrew.goodbody at linaro.org
Thu Jun 26 10:21:07 CEST 2025


On 26/06/2025 09:05, Heinrich Schuchardt wrote:
> On 25.06.25 19:15, Ilias Apalodimas wrote:
>> This variable might end up being uninitialized if we exit early.

This commit message could maybe do with expanding a little to make it 
clearer, see below.

>> Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
>> ---
>>   lib/efi_loader/efi_bootmgr.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
>> index b9437a81c642..662993fb8095 100644
>> --- a/lib/efi_loader/efi_bootmgr.c
>> +++ b/lib/efi_loader/efi_bootmgr.c
>> @@ -1134,7 +1134,7 @@ efi_status_t 
>> efi_bootmgr_update_media_device_boot_option(void)
>>   {
>>       u32 i;
>>       efi_status_t ret;
>> -    efi_uintn_t count, num, total;
>> +    efi_uintn_t count, num, total = 0;
> 
> 'total' is a non-static local variable.
> The first line using it in origin/next initializes the variable:
> 
>      total = num;
> 
> If we exit early, local variables are discarded.
> Could you, please, explain your concern.

The issue is taking a 'goto out' before total is initialised. 'out:' 
uses the value of total so you can execute that code without having 
initialised total.

FWIW this was also found by Smatch and is in my list to address.

Andrew

> Best regards
> 
> Heinrich
> 
>>       efi_handle_t *handles = NULL;
>>       struct eficonfig_media_boot_option *opt = NULL;
>>
>> -- 
>> 2.49.0
>>
> 



More information about the U-Boot mailing list