summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-05-13 20:18:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-14 12:47:47 -0400
commit23091e287355440fb680868c23bcada594d3f399 (patch)
tree3e5849ce48e8dc9c758aee5bfdbc8b23db5a98d1
parent54c7a8916a887f357088f99e9c3a7720cd57d2c8 (diff)
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.de Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Mike 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--init/initramfs.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/init/initramfs.c b/init/initramfs.c
index c322e1099f43..5fda9557a134 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -518,37 +518,35 @@ extern unsigned long __initramfs_size;
518#include <linux/initrd.h> 518#include <linux/initrd.h>
519#include <linux/kexec.h> 519#include <linux/kexec.h>
520 520
521static void __init free_initrd(void)
522{
523#ifdef CONFIG_KEXEC_CORE 521#ifdef CONFIG_KEXEC_CORE
522static bool kexec_free_initrd(void)
523{
524 unsigned long crashk_start = (unsigned long)__va(crashk_res.start); 524 unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
525 unsigned long crashk_end = (unsigned long)__va(crashk_res.end); 525 unsigned long crashk_end = (unsigned long)__va(crashk_res.end);
526#endif
527 if (do_retain_initrd)
528 goto skip;
529 526
530#ifdef CONFIG_KEXEC_CORE
531 /* 527 /*
532 * If the initrd region is overlapped with crashkernel reserved region, 528 * If the initrd region is overlapped with crashkernel reserved region,
533 * free only memory that is not part of crashkernel region. 529 * free only memory that is not part of crashkernel region.
534 */ 530 */
535 if (initrd_start < crashk_end && initrd_end > crashk_start) { 531 if (initrd_start >= crashk_end || initrd_end <= crashk_start)
536 /* 532 return false;
537 * Initialize initrd memory region since the kexec boot does 533
538 * not do. 534 /*
539 */ 535 * Initialize initrd memory region since the kexec boot does not do.
540 memset((void *)initrd_start, 0, initrd_end - initrd_start); 536 */
541 if (initrd_start < crashk_start) 537 memset((void *)initrd_start, 0, initrd_end - initrd_start);
542 free_initrd_mem(initrd_start, crashk_start); 538 if (initrd_start < crashk_start)
543 if (initrd_end > crashk_end) 539 free_initrd_mem(initrd_start, crashk_start);
544 free_initrd_mem(crashk_end, initrd_end); 540 if (initrd_end > crashk_end)
545 } else 541 free_initrd_mem(crashk_end, initrd_end);
546#endif 542 return true;
547 free_initrd_mem(initrd_start, initrd_end);
548skip:
549 initrd_start = 0;
550 initrd_end = 0;
551} 543}
544#else
545static inline bool kexec_free_initrd(void)
546{
547 return false;
548}
549#endif /* CONFIG_KEXEC_CORE */
552 550
553#ifdef CONFIG_BLK_DEV_RAM 551#ifdef CONFIG_BLK_DEV_RAM
554#define BUF_SIZE 1024 552#define BUF_SIZE 1024
@@ -642,7 +640,16 @@ static int __init populate_rootfs(void)
642 printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); 640 printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
643#endif 641#endif
644 } 642 }
645 free_initrd(); 643
644 /*
645 * If the initrd region is overlapped with crashkernel reserved region,
646 * free only memory that is not part of crashkernel region.
647 */
648 if (!do_retain_initrd && !kexec_free_initrd())
649 free_initrd_mem(initrd_start, initrd_end);
650 initrd_start = 0;
651 initrd_end = 0;
652
646 flush_delayed_fput(); 653 flush_delayed_fput();
647 return 0; 654 return 0;
648} 655}