@@ -29,7 +29,7 @@ const struct kexec_file_ops * const kexec_file_loaders[] = {
int arch_kimage_file_post_load_cleanup(struct kimage *image)
{
- vfree(image->arch.dtb);
+ of_free_fdt(image->arch.dtb);
image->arch.dtb = NULL;
vfree(image->arch.elf_headers);
@@ -57,36 +57,19 @@ static int create_dtb(struct kimage *image,
cmdline_len = cmdline ? strlen(cmdline) : 0;
buf_size = fdt_totalsize(initial_boot_params)
+ cmdline_len + DTB_EXTRA_SPACE;
-
- for (;;) {
- buf = vmalloc(buf_size);
- if (!buf)
- return -ENOMEM;
-
- /* duplicate a device tree blob */
- ret = fdt_open_into(initial_boot_params, buf, buf_size);
- if (ret)
- return -EINVAL;
-
- ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr,
+ buf = of_alloc_and_init_fdt(buf_size);
+ if (!buf)
+ return -ENOMEM;
+ ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr,
initrd_len, cmdline);
- if (ret) {
- vfree(buf);
- if (ret == -ENOMEM) {
- /* unlikely, but just in case */
- buf_size += DTB_EXTRA_SPACE;
- continue;
- } else {
- return ret;
- }
- }
-
+ if (!ret) {
/* trim it */
fdt_pack(buf);
*dtb = buf;
+ } else
+ of_free_fdt(buf);
- return 0;
- }
+ return ret;
}
static int prepare_elf_headers(void **addr, unsigned long *sz)
@@ -224,6 +207,6 @@ int load_other_segments(struct kimage *image,
out_err:
image->nr_segments = orig_segments;
- vfree(dtb);
+ of_free_fdt(dtb);
return ret;
}
of_alloc_and_init_fdt() and of_free_fdt() have been defined in drivers/of/kexec.c to allocate and free memory for FDT. Use of_alloc_and_init_fdt() and of_free_fdt() to allocate and initialize the FDT, and to free the FDT respectively. Signed-off-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com> Suggested-by: Rob Herring <robh@kernel.org> --- arch/arm64/kernel/machine_kexec_file.c | 37 +++++++------------------- 1 file changed, 10 insertions(+), 27 deletions(-)