Fix incorrect return code of boot option update

Correct the return code for out-of-memory and no boot option found

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 01daddc..987b168 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -352,7 +352,7 @@
 		 * a architecture-specific default image name such as BOOTAA64.EFI.
 		 */
 		efi_ret = efi_bootmgr_update_media_device_boot_option();
-		if (efi_ret != EFI_SUCCESS && efi_ret != EFI_NOT_FOUND)
+		if (efi_ret != EFI_SUCCESS)
 			goto cleanup;
 
 		ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 82a8030..e6e8a0a 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -2314,7 +2314,7 @@
 		return CMD_RET_FAILURE;
 
 	ret = efi_bootmgr_update_media_device_boot_option();
-	if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND)
+	if (ret != EFI_SUCCESS)
 		return ret;
 
 	while (1) {
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index f6110f2..993bb11 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -660,11 +660,13 @@
 					   NULL, &count,
 					   (efi_handle_t **)&volume_handles);
 	if (ret != EFI_SUCCESS)
-		return ret;
+		goto out;
 
 	opt = calloc(count, sizeof(struct eficonfig_media_boot_option));
-	if (!opt)
+	if (!opt) {
+		ret = EFI_OUT_OF_RESOURCES;
 		goto out;
+	}
 
 	/* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */
 	ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, count);
@@ -717,5 +719,7 @@
 	free(opt);
 	efi_free_pool(volume_handles);
 
+	if (ret == EFI_NOT_FOUND)
+		return EFI_SUCCESS;
 	return ret;
 }