[U-Boot] [PATCH 06/18] efi_loader: efi_net: check return value of calloc

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Oct 26 17:25:47 UTC 2017


Calloc may return NULL. So we must check the return value.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 lib/efi_loader/efi_net.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c
index 432d9a99a2..a7b101e830 100644
--- a/lib/efi_loader/efi_net.c
+++ b/lib/efi_loader/efi_net.c
@@ -292,6 +292,10 @@ int efi_net_register(void)
 
 	/* We only expose the "active" eth device, so one is enough */
 	netobj = calloc(1, sizeof(*netobj));
+	if (!netobj) {
+		printf("ERROR: Out of memory\n");
+		return 1;
+	}
 
 	/* Fill in object data */
 	netobj->parent.protocols[0].guid = &efi_net_guid;
-- 
2.11.0



More information about the U-Boot mailing list