diff options
author | Christoph Hellwig <hch@lst.de> | 2019-05-13 20:18:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-05-14 12:47:47 -0400 |
commit | 54c7a8916a887f357088f99e9c3a7720cd57d2c8 (patch) | |
tree | 02d045ecbf715fcaedc470ac474eea89d7818cae /init | |
parent | 1df3a339074e31db95c4790ea9236874b13ccd87 (diff) |
initramfs: free initrd memory if opening /initrd.image fails
Patch series "initramfs tidyups".
I've spent some time chasing down behavior in initramfs and found
plenty of opportunity to improve the code. A first stab on that is
contained in this series.
This patch (of 7):
We free the initrd memory for all successful or error cases except for the
case where opening /initrd.image fails, which looks like an oversight.
Steven said:
: This also changes the behaviour when CONFIG_INITRAMFS_FORCE is enabled
: - specifically it means that the initrd is freed (previously it was
: ignored and never freed). But that seems like reasonable behaviour and
: the previous behaviour looks like another oversight.
Link: http://lkml.kernel.org/r/20190213174621.29297-3-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Steven Price <steven.price@arm.com>
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: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'init')
-rw-r--r-- | init/initramfs.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/init/initramfs.c b/init/initramfs.c index 4749e1115eef..c322e1099f43 100644 --- a/init/initramfs.c +++ b/init/initramfs.c | |||
@@ -612,13 +612,12 @@ static int __init populate_rootfs(void) | |||
612 | printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); | 612 | printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); |
613 | err = unpack_to_rootfs((char *)initrd_start, | 613 | err = unpack_to_rootfs((char *)initrd_start, |
614 | initrd_end - initrd_start); | 614 | initrd_end - initrd_start); |
615 | if (!err) { | 615 | if (!err) |
616 | free_initrd(); | ||
617 | goto done; | 616 | goto done; |
618 | } else { | 617 | |
619 | clean_rootfs(); | 618 | clean_rootfs(); |
620 | unpack_to_rootfs(__initramfs_start, __initramfs_size); | 619 | unpack_to_rootfs(__initramfs_start, __initramfs_size); |
621 | } | 620 | |
622 | printk(KERN_INFO "rootfs image is not initramfs (%s)" | 621 | printk(KERN_INFO "rootfs image is not initramfs (%s)" |
623 | "; looks like an initrd\n", err); | 622 | "; looks like an initrd\n", err); |
624 | fd = ksys_open("/initrd.image", | 623 | fd = ksys_open("/initrd.image", |
@@ -632,7 +631,6 @@ static int __init populate_rootfs(void) | |||
632 | written, initrd_end - initrd_start); | 631 | written, initrd_end - initrd_start); |
633 | 632 | ||
634 | ksys_close(fd); | 633 | ksys_close(fd); |
635 | free_initrd(); | ||
636 | } | 634 | } |
637 | done: | 635 | done: |
638 | /* empty statement */; | 636 | /* empty statement */; |
@@ -642,9 +640,9 @@ static int __init populate_rootfs(void) | |||
642 | initrd_end - initrd_start); | 640 | initrd_end - initrd_start); |
643 | if (err) | 641 | if (err) |
644 | printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); | 642 | printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); |
645 | free_initrd(); | ||
646 | #endif | 643 | #endif |
647 | } | 644 | } |
645 | free_initrd(); | ||
648 | flush_delayed_fput(); | 646 | flush_delayed_fput(); |
649 | return 0; | 647 | return 0; |
650 | } | 648 | } |