Commit 23091e28 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

initramfs: cleanup initrd freeing

Factor the kexec logic into a separate helper, and then inline the rest of
free_initrd into the only caller.

Link: http://lkml.kernel.org/r/20190213174621.29297-4-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>	[arm64]
Cc: Geert Uytterhoeven <geert@linux-m68k.org>	[m68k]
Cc: Steven Price <steven.price@arm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 54c7a891
...@@ -518,37 +518,35 @@ extern unsigned long __initramfs_size; ...@@ -518,37 +518,35 @@ extern unsigned long __initramfs_size;
#include <linux/initrd.h> #include <linux/initrd.h>
#include <linux/kexec.h> #include <linux/kexec.h>
static void __init free_initrd(void)
{
#ifdef CONFIG_KEXEC_CORE #ifdef CONFIG_KEXEC_CORE
static bool kexec_free_initrd(void)
{
unsigned long crashk_start = (unsigned long)__va(crashk_res.start); unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
unsigned long crashk_end = (unsigned long)__va(crashk_res.end); unsigned long crashk_end = (unsigned long)__va(crashk_res.end);
#endif
if (do_retain_initrd)
goto skip;
#ifdef CONFIG_KEXEC_CORE
/* /*
* If the initrd region is overlapped with crashkernel reserved region, * If the initrd region is overlapped with crashkernel reserved region,
* free only memory that is not part of crashkernel region. * free only memory that is not part of crashkernel region.
*/ */
if (initrd_start < crashk_end && initrd_end > crashk_start) { if (initrd_start >= crashk_end || initrd_end <= crashk_start)
return false;
/* /*
* Initialize initrd memory region since the kexec boot does * Initialize initrd memory region since the kexec boot does not do.
* not do.
*/ */
memset((void *)initrd_start, 0, initrd_end - initrd_start); memset((void *)initrd_start, 0, initrd_end - initrd_start);
if (initrd_start < crashk_start) if (initrd_start < crashk_start)
free_initrd_mem(initrd_start, crashk_start); free_initrd_mem(initrd_start, crashk_start);
if (initrd_end > crashk_end) if (initrd_end > crashk_end)
free_initrd_mem(crashk_end, initrd_end); free_initrd_mem(crashk_end, initrd_end);
} else return true;
#endif }
free_initrd_mem(initrd_start, initrd_end); #else
skip: static inline bool kexec_free_initrd(void)
initrd_start = 0; {
initrd_end = 0; return false;
} }
#endif /* CONFIG_KEXEC_CORE */
#ifdef CONFIG_BLK_DEV_RAM #ifdef CONFIG_BLK_DEV_RAM
#define BUF_SIZE 1024 #define BUF_SIZE 1024
...@@ -642,7 +640,16 @@ static int __init populate_rootfs(void) ...@@ -642,7 +640,16 @@ static int __init populate_rootfs(void)
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
#endif #endif
} }
free_initrd();
/*
* If the initrd region is overlapped with crashkernel reserved region,
* free only memory that is not part of crashkernel region.
*/
if (!do_retain_initrd && !kexec_free_initrd())
free_initrd_mem(initrd_start, initrd_end);
initrd_start = 0;
initrd_end = 0;
flush_delayed_fput(); flush_delayed_fput();
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment