[U-Boot] [PATCH v2 07/18] efi_loader: efi_disk: use efi_add_protocol

Heinrich Schuchardt xypron.glpk at gmx.de
Fri Nov 17 22:25:17 UTC 2017


On 11/17/2017 03:06 PM, Simon Glass wrote:
> On 12 November 2017 at 07:02, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>> Use efi_add_protocol to install protocols.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
>> ---
>> v2
>>          no change
>> ---
>>   lib/efi_loader/efi_disk.c | 39 +++++++++++++++++++++++----------------
>>   1 file changed, 23 insertions(+), 16 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg at chromium.org>
> 
> See below.
> 
>>
>> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
>> index c6f0d732c1..1d6cf3122f 100644
>> --- a/lib/efi_loader/efi_disk.c
>> +++ b/lib/efi_loader/efi_disk.c
>> @@ -213,33 +213,40 @@ static void efi_disk_add_dev(const char *name,
>>                               unsigned int part)
>>   {
>>          struct efi_disk_obj *diskobj;
>> +       efi_status_t ret;
>>
>>          /* Don't add empty devices */
>>          if (!desc->lba)
>>                  return;
>>
>>          diskobj = calloc(1, sizeof(*diskobj));
>> -       if (!diskobj) {
>> -               printf("ERROR: Out of memory\n");
>> -               return;
>> -       }
>> +       if (!diskobj)
>> +               goto out_of_memory;
>> +
>> +       /* Hook up to the device list */
>> +       list_add_tail(&diskobj->parent.link, &efi_obj_list);
>>
>>          /* Fill in object data */
>>          diskobj->dp = efi_dp_from_part(desc, part);
>>          diskobj->part = part;
>> -       diskobj->parent.protocols[0].guid = &efi_block_io_guid;
>> -       diskobj->parent.protocols[0].protocol_interface = &diskobj->ops;
>> -       diskobj->parent.protocols[1].guid = &efi_guid_device_path;
>> -       diskobj->parent.protocols[1].protocol_interface = diskobj->dp;
>> +       diskobj->parent.handle = diskobj;
>> +       ret = efi_add_protocol(diskobj->parent.handle, &efi_block_io_guid,
>> +                              &diskobj->ops);
>> +       if (ret != EFI_SUCCESS)
>> +               goto out_of_memory;
>> +       ret = efi_add_protocol(diskobj->parent.handle, &efi_guid_device_path,
>> +                              diskobj->dp);
>> +       if (ret != EFI_SUCCESS)
>> +               goto out_of_memory;
>>          if (part >= 1) {
>>                  diskobj->volume = efi_simple_file_system(desc, part,
>>                                                           diskobj->dp);
>> -               diskobj->parent.protocols[2].guid =
>> -                       &efi_simple_file_system_protocol_guid;
>> -               diskobj->parent.protocols[2].protocol_interface =
>> -                       diskobj->volume;
>> +               ret = efi_add_protocol(diskobj->parent.handle,
>> +                                      &efi_simple_file_system_protocol_guid,
>> +                                      &diskobj->volume);
>> +               if (ret != EFI_SUCCESS)
>> +                       goto out_of_memory;
>>          }
>> -       diskobj->parent.handle = diskobj;
>>          diskobj->ops = block_io_disk_template;
>>          diskobj->ifname = if_typename;
>>          diskobj->dev_index = dev_index;
>> @@ -253,9 +260,9 @@ static void efi_disk_add_dev(const char *name,
>>          diskobj->media.io_align = desc->blksz;
>>          diskobj->media.last_block = desc->lba - offset;
>>          diskobj->ops.media = &diskobj->media;
>> -
>> -       /* Hook up to the device list */
>> -       list_add_tail(&diskobj->parent.link, &efi_obj_list);
>> +       return;
>> +out_of_memory:
>> +       printf("ERROR: Out of memory\n");
> 
> Can we not return this error?

This get's called when executing the bootefi command before the image is 
loaded.
Is there really anything better than writing a message?
Anyway if we have that little memory when coming from the U-Boot command 
line we are in deep trouble.

Thanks for all your reviewing.

Best regards

Heinrich

> 
>>   }
>>
>>   static int efi_disk_create_eltorito(struct blk_desc *desc,
>> --
>> 2.15.0
>>
> 



More information about the U-Boot mailing list