diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index d20775eccd99c709aab87c20c21afad6f91bcf22..3196d86040729487186c241e9b7c36d597bbb6f2 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -158,7 +158,7 @@ static void *copy_fdt(void *fdt)
 	}
 
 	/* Give us at least 4kb breathing room */
-	fdt_size = ALIGN(fdt_size + 4096, 4096);
+	fdt_size = ALIGN(fdt_size + 4096, EFI_PAGE_SIZE);
 	fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
 
 	/* Safe fdt location is at 128MB */
@@ -166,7 +166,7 @@ static void *copy_fdt(void *fdt)
 	if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
 			       &new_fdt_addr) != EFI_SUCCESS) {
 		/* If we can't put it there, put it somewhere */
-		new_fdt_addr = (ulong)memalign(4096, fdt_size);
+		new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size);
 		if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
 				       &new_fdt_addr) != EFI_SUCCESS) {
 			printf("ERROR: Failed to reserve space for FDT\n");
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 037cc7c543414682ebe05f11da5df17764a80a81..1179234f6836b6e7aaa942cbed3e1a701aee2737 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -33,9 +33,9 @@ const char *__efi_nesting_dec(void);
  * Exit the u-boot world back to UEFI:
  */
 #define EFI_EXIT(ret) ({ \
-	efi_status_t _r = ret; \
+	typeof(ret) _r = ret; \
 	debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \
-		__func__, (u32)(_r & ~EFI_ERROR_MASK)); \
+		__func__, (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \
 	assert(__efi_exit_check()); \
 	_r; \
 	})
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 59479eddb9d877d8d27ca026262db725ff04229d..43f32385fae01fbdbbcfdbae2e9c4d78e7918477 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -611,7 +611,7 @@ static int efi_search(enum efi_locate_search_type search_type,
 	return -1;
 }
 
-static efi_status_t EFIAPI efi_locate_handle(
+static efi_status_t efi_locate_handle(
 			enum efi_locate_search_type search_type,
 			efi_guid_t *protocol, void *search_key,
 			unsigned long *buffer_size, efi_handle_t *buffer)
@@ -633,6 +633,10 @@ static efi_status_t EFIAPI efi_locate_handle(
 		return EFI_BUFFER_TOO_SMALL;
 	}
 
+	*buffer_size = size;
+	if (size == 0)
+		return EFI_NOT_FOUND;
+
 	/* Then fill the array */
 	list_for_each(lhandle, &efi_obj_list) {
 		struct efi_object *efiobj;
@@ -642,7 +646,6 @@ static efi_status_t EFIAPI efi_locate_handle(
 		}
 	}
 
-	*buffer_size = size;
 	return EFI_SUCCESS;
 }
 
diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
index e063e0c79b7e2f9f767eb47e44e8d5d867447c79..411a8c9226154d922ddcc948c96f1ab7660f7c23 100644
--- a/lib/efi_loader/efi_gop.c
+++ b/lib/efi_loader/efi_gop.c
@@ -137,7 +137,7 @@ int efi_gop_register(void)
 	struct udevice *vdev;
 
 	/* We only support a single video output device for now */
-	if (uclass_first_device(UCLASS_VIDEO, &vdev))
+	if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev)
 		return -1;
 
 	struct video_priv *priv = dev_get_uclass_priv(vdev);
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index dd52755d1d707706211e2d5101503590efa009c2..ad7f3754bd0970b5209f756d5f1d7ce4883e4587 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -325,7 +325,7 @@ void efi_add_runtime_mmio(void *mmio_ptr, u64 len)
 {
 	struct efi_runtime_mmio_list *newmmio;
 
-	u64 pages = (len + EFI_PAGE_SIZE - 1) >> EFI_PAGE_SHIFT;
+	u64 pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
 	efi_add_memory_map(*(uintptr_t *)mmio_ptr, pages, EFI_MMAP_IO, false);
 
 	newmmio = calloc(1, sizeof(*newmmio));