Commit 84d14568ca1a70ffd8925c357e3db2a6a8437922
Committed by
Alexander Graf
1 parent
4b9f7aaf7c
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
efi_loader: efi_net: use efi_add_protocol
Use efi_add_protocol to add protocols. 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 1 changed file with 20 additions and 14 deletions Side-by-side Diff
lib/efi_loader/efi_net.c
... | ... | @@ -292,20 +292,26 @@ |
292 | 292 | |
293 | 293 | /* We only expose the "active" eth device, so one is enough */ |
294 | 294 | netobj = calloc(1, sizeof(*netobj)); |
295 | - if (!netobj) { | |
296 | - printf("ERROR: Out of memory\n"); | |
297 | - return 1; | |
298 | - } | |
295 | + if (!netobj) | |
296 | + goto out_of_memory; | |
299 | 297 | |
298 | + /* Hook net up to the device list */ | |
299 | + list_add_tail(&netobj->parent.link, &efi_obj_list); | |
300 | + | |
300 | 301 | /* Fill in object data */ |
301 | - netobj->parent.protocols[0].guid = &efi_net_guid; | |
302 | - netobj->parent.protocols[0].protocol_interface = &netobj->net; | |
303 | - netobj->parent.protocols[1].guid = &efi_guid_device_path; | |
304 | - netobj->parent.protocols[1].protocol_interface = | |
305 | - efi_dp_from_eth(); | |
306 | - netobj->parent.protocols[2].guid = &efi_pxe_guid; | |
307 | - netobj->parent.protocols[2].protocol_interface = &netobj->pxe; | |
308 | 302 | netobj->parent.handle = &netobj->net; |
303 | + r = efi_add_protocol(netobj->parent.handle, &efi_net_guid, | |
304 | + &netobj->net); | |
305 | + if (r != EFI_SUCCESS) | |
306 | + goto out_of_memory; | |
307 | + r = efi_add_protocol(netobj->parent.handle, &efi_guid_device_path, | |
308 | + efi_dp_from_eth()); | |
309 | + if (r != EFI_SUCCESS) | |
310 | + goto out_of_memory; | |
311 | + r = efi_add_protocol(netobj->parent.handle, &efi_pxe_guid, | |
312 | + &netobj->pxe); | |
313 | + if (r != EFI_SUCCESS) | |
314 | + goto out_of_memory; | |
309 | 315 | netobj->net.revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION; |
310 | 316 | netobj->net.start = efi_net_start; |
311 | 317 | netobj->net.stop = efi_net_stop; |
... | ... | @@ -330,9 +336,6 @@ |
330 | 336 | if (dhcp_ack) |
331 | 337 | netobj->pxe_mode.dhcp_ack = *dhcp_ack; |
332 | 338 | |
333 | - /* Hook net up to the device list */ | |
334 | - list_add_tail(&netobj->parent.link, &efi_obj_list); | |
335 | - | |
336 | 339 | /* |
337 | 340 | * Create WaitForPacket event. |
338 | 341 | */ |
... | ... | @@ -365,5 +368,8 @@ |
365 | 368 | } |
366 | 369 | |
367 | 370 | return 0; |
371 | +out_of_memory: | |
372 | + printf("ERROR: Out of memory\n"); | |
373 | + return 1; | |
368 | 374 | } |