Commit 44549d62c31dc433366b4c5d6e58e0e3091e542b
Committed by
Alexander Graf
1 parent
ea54ad5928
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
efi_loader: helper function to add EFI object to list
To avoid duplicate coding provide a helper function that initializes an EFI object and adds it to the EFI object list. efi_exit() is the only place where we dereference a handle to obtain a protocol interface. Add a comment to the function. Suggested-by: Alexander Graf <agraf@suse.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Showing 5 changed files with 38 additions and 16 deletions Side-by-side Diff
include/efi_loader.h
... | ... | @@ -186,6 +186,8 @@ |
186 | 186 | void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map); |
187 | 187 | /* Call this to set the current device name */ |
188 | 188 | void efi_set_bootdev(const char *dev, const char *devnr, const char *path); |
189 | +/* Add a new object to the object list. */ | |
190 | +void efi_add_handle(struct efi_object *obj); | |
189 | 191 | /* Create handle */ |
190 | 192 | efi_status_t efi_create_handle(void **handle); |
191 | 193 | /* Call this to validate a handle and find the EFI object for it */ |
lib/efi_loader/efi_boottime.c
... | ... | @@ -322,6 +322,23 @@ |
322 | 322 | } |
323 | 323 | |
324 | 324 | /* |
325 | + * Add a new object to the object list. | |
326 | + * | |
327 | + * The protocols list is initialized. | |
328 | + * The object handle is set. | |
329 | + * | |
330 | + * @obj object to be added | |
331 | + */ | |
332 | +void efi_add_handle(struct efi_object *obj) | |
333 | +{ | |
334 | + if (!obj) | |
335 | + return; | |
336 | + INIT_LIST_HEAD(&obj->protocols); | |
337 | + obj->handle = obj; | |
338 | + list_add_tail(&obj->link, &efi_obj_list); | |
339 | +} | |
340 | + | |
341 | +/* | |
325 | 342 | * Create handle. |
326 | 343 | * |
327 | 344 | * @handle new handle |
... | ... | @@ -337,11 +354,8 @@ |
337 | 354 | (void **)&obj); |
338 | 355 | if (r != EFI_SUCCESS) |
339 | 356 | return r; |
340 | - memset(obj, 0, sizeof(struct efi_object)); | |
341 | - obj->handle = obj; | |
342 | - INIT_LIST_HEAD(&obj->protocols); | |
343 | - list_add_tail(&obj->link, &efi_obj_list); | |
344 | - *handle = obj; | |
357 | + efi_add_handle(obj); | |
358 | + *handle = obj->handle; | |
345 | 359 | return r; |
346 | 360 | } |
347 | 361 | |
348 | 362 | |
... | ... | @@ -1163,14 +1177,15 @@ |
1163 | 1177 | { |
1164 | 1178 | efi_status_t ret; |
1165 | 1179 | |
1180 | + /* Add internal object to object list */ | |
1181 | + efi_add_handle(obj); | |
1182 | + /* efi_exit() assumes that the handle points to the info */ | |
1166 | 1183 | obj->handle = info; |
1167 | 1184 | |
1168 | 1185 | info->file_path = file_path; |
1169 | 1186 | if (device_path) |
1170 | 1187 | info->device_handle = efi_dp_find_obj(device_path, NULL); |
1171 | 1188 | |
1172 | - INIT_LIST_HEAD(&obj->protocols); | |
1173 | - list_add_tail(&obj->link, &efi_obj_list); | |
1174 | 1189 | /* |
1175 | 1190 | * When asking for the device path interface, return |
1176 | 1191 | * bootefi_device_path |
... | ... | @@ -1379,6 +1394,17 @@ |
1379 | 1394 | efi_status_t exit_status, unsigned long exit_data_size, |
1380 | 1395 | int16_t *exit_data) |
1381 | 1396 | { |
1397 | + /* | |
1398 | + * We require that the handle points to the original loaded | |
1399 | + * image protocol interface. | |
1400 | + * | |
1401 | + * For getting the longjmp address this is safer than locating | |
1402 | + * the protocol because the protocol may have been reinstalled | |
1403 | + * pointing to another memory location. | |
1404 | + * | |
1405 | + * TODO: We should call the unload procedure of the loaded | |
1406 | + * image protocol. | |
1407 | + */ | |
1382 | 1408 | struct efi_loaded_image *loaded_image_info = (void*)image_handle; |
1383 | 1409 | |
1384 | 1410 | EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, |
lib/efi_loader/efi_disk.c
... | ... | @@ -224,13 +224,11 @@ |
224 | 224 | goto out_of_memory; |
225 | 225 | |
226 | 226 | /* Hook up to the device list */ |
227 | - INIT_LIST_HEAD(&diskobj->parent.protocols); | |
228 | - list_add_tail(&diskobj->parent.link, &efi_obj_list); | |
227 | + efi_add_handle(&diskobj->parent); | |
229 | 228 | |
230 | 229 | /* Fill in object data */ |
231 | 230 | diskobj->dp = efi_dp_from_part(desc, part); |
232 | 231 | diskobj->part = part; |
233 | - diskobj->parent.handle = diskobj; | |
234 | 232 | ret = efi_add_protocol(diskobj->parent.handle, &efi_block_io_guid, |
235 | 233 | &diskobj->ops); |
236 | 234 | if (ret != EFI_SUCCESS) |
lib/efi_loader/efi_gop.c
... | ... | @@ -180,11 +180,9 @@ |
180 | 180 | } |
181 | 181 | |
182 | 182 | /* Hook up to the device list */ |
183 | - INIT_LIST_HEAD(&gopobj->parent.protocols); | |
184 | - list_add_tail(&gopobj->parent.link, &efi_obj_list); | |
183 | + efi_add_handle(&gopobj->parent); | |
185 | 184 | |
186 | 185 | /* Fill in object data */ |
187 | - gopobj->parent.handle = &gopobj->ops; | |
188 | 186 | ret = efi_add_protocol(gopobj->parent.handle, &efi_gop_guid, |
189 | 187 | &gopobj->ops); |
190 | 188 | if (ret != EFI_SUCCESS) { |
lib/efi_loader/efi_net.c
... | ... | @@ -296,11 +296,9 @@ |
296 | 296 | goto out_of_memory; |
297 | 297 | |
298 | 298 | /* Hook net up to the device list */ |
299 | - INIT_LIST_HEAD(&netobj->parent.protocols); | |
300 | - list_add_tail(&netobj->parent.link, &efi_obj_list); | |
299 | + efi_add_handle(&netobj->parent); | |
301 | 300 | |
302 | 301 | /* Fill in object data */ |
303 | - netobj->parent.handle = &netobj->net; | |
304 | 302 | r = efi_add_protocol(netobj->parent.handle, &efi_net_guid, |
305 | 303 | &netobj->net); |
306 | 304 | if (r != EFI_SUCCESS) |