From f28eb4856d7c9b3711d581095ea304b42023d4f0 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 6 May 2019 18:39:22 +0000 Subject: [PATCH] We only ever need one devinfo per handle. So allocate it outside of looping over the filesystem modules rather than doing a malloc + free each time through the loop. In addition, nothing changes from loop to loop, so setup the new devinfo outside the loop as well. --- stand/efi/boot1/boot1.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/stand/efi/boot1/boot1.c b/stand/efi/boot1/boot1.c index 5b3b1d6d18cf..bc32f7e84530 100644 --- a/stand/efi/boot1/boot1.c +++ b/stand/efi/boot1/boot1.c @@ -264,24 +264,24 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, BOOLEAN *preferred) *preferred = efi_devpath_match(imgpath, devpath); /* Run through each module, see if it can load this partition */ - for (i = 0; i < NUM_BOOT_MODULES; i++) { - devinfo = malloc(sizeof(*devinfo)); - if (devinfo == NULL) { - DPRINTF("\nFailed to allocate devinfo\n"); - break; - } - devinfo->dev = blkio; - devinfo->devpath = devpath; - devinfo->devhandle = h; - devinfo->devdata = NULL; - devinfo->preferred = *preferred; - devinfo->next = NULL; + devinfo = malloc(sizeof(*devinfo)); + if (devinfo == NULL) { + DPRINTF("\nFailed to allocate devinfo\n"); + return (EFI_UNSUPPORTED); + } + devinfo->dev = blkio; + devinfo->devpath = devpath; + devinfo->devhandle = h; + devinfo->preferred = *preferred; + devinfo->next = NULL; + for (i = 0; i < NUM_BOOT_MODULES; i++) { + devinfo->devdata = NULL; status = boot_modules[i]->probe(devinfo); if (status == EFI_SUCCESS) return (EFI_SUCCESS); - free(devinfo); } + free(devinfo); return (EFI_UNSUPPORTED); }