Use simple malloc/free instead of dropping down to the UEFI

BootServices AllocatePool/FreePool calls. They are simpler to use and
result in the same thing happening.

Reviewed by: tsoome@
Differential Revision: https://reviews.freebsd.org/D20540
This commit is contained in:
Warner Losh 2019-06-06 21:04:37 +00:00
parent e5b6bcc7d2
commit fef7bfef6f
2 changed files with 16 additions and 18 deletions

View File

@ -167,18 +167,18 @@ load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize)
return (EFI_INVALID_PARAMETER);
}
if ((status = BS->AllocatePool(EfiLoaderData, size, &buf)) !=
EFI_SUCCESS) {
printf("Failed to allocate read buffer %zu for '%s' (%lu)\n",
size, filepath, EFI_ERROR_CODE(status));
return (status);
buf = malloc(size);
if (buf == NULL) {
printf("Failed to allocate read buffer %zu for '%s'\n",
size, filepath);
return (EFI_OUT_OF_RESOURCES);
}
read = fsread(ino, buf, size);
if ((size_t)read != size) {
printf("Failed to read '%s' (%zd != %zu)\n", filepath, read,
size);
(void)BS->FreePool(buf);
free(buf);
return (EFI_INVALID_PARAMETER);
}

View File

@ -115,19 +115,17 @@ probe(dev_info_t *dev)
{
spa_t *spa;
dev_info_t *tdev;
EFI_STATUS status;
/* ZFS consumes the dev on success so we need a copy. */
if ((status = BS->AllocatePool(EfiLoaderData, sizeof(*dev),
(void**)&tdev)) != EFI_SUCCESS) {
DPRINTF("Failed to allocate tdev (%lu)\n",
EFI_ERROR_CODE(status));
return (status);
tdev = malloc(sizeof(*dev));
if (tdev == NULL) {
DPRINTF("Failed to allocate tdev\n");
return (EFI_OUT_OF_RESOURCES);
}
memcpy(tdev, dev, sizeof(*dev));
if (vdev_probe(vdev_read, tdev, &spa) != 0) {
(void)BS->FreePool(tdev);
free(tdev);
return (EFI_UNSUPPORTED);
}
@ -185,17 +183,17 @@ load(const char *filepath, dev_info_t *devinfo, void **bufp, size_t *bufsize)
return (EFI_INVALID_PARAMETER);
}
if ((status = BS->AllocatePool(EfiLoaderData, (UINTN)st.st_size, &buf))
!= EFI_SUCCESS) {
printf("Failed to allocate load buffer %jd for pool '%s' for '%s' "
"(%lu)\n", (intmax_t)st.st_size, spa->spa_name, filepath, EFI_ERROR_CODE(status));
buf = malloc(st.st_size);
if (buf == NULL) {
printf("Failed to allocate load buffer %jd for pool '%s' for '%s' ",
(intmax_t)st.st_size, spa->spa_name, filepath);
return (EFI_INVALID_PARAMETER);
}
if ((err = dnode_read(spa, &dn, 0, buf, st.st_size)) != 0) {
printf("Failed to read node from %s (%d)\n", spa->spa_name,
err);
(void)BS->FreePool(buf);
free(buf);
return (EFI_INVALID_PARAMETER);
}