The patch titled Subject: initramfs: free initrd memory if opening /initrd.image fails has been added to the -mm tree. Its filename is initramfs-free-initrd-memory-if-opening-initrdimage-fails.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/initramfs-free-initrd-memory-if-opening-initrdimage-fails.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/initramfs-free-initrd-memory-if-opening-initrdimage-fails.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Christoph Hellwig <hch@xxxxxx> Subject: 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@xxxxxx Signed-off-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: Steven Price <steven.price@xxxxxxx> Acked-by: Mike Rapoport <rppt@xxxxxxxxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> [arm64] Cc: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> [m68k] Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Russell King <linux@xxxxxxxxxxxxxxx> Cc: Will Deacon <will.deacon@xxxxxxx> Cc: Guan Xuetao <gxt@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- init/initramfs.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) --- a/init/initramfs.c~initramfs-free-initrd-memory-if-opening-initrdimage-fails +++ a/init/initramfs.c @@ -612,13 +612,12 @@ static int __init populate_rootfs(void) printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start); - if (!err) { - free_initrd(); + if (!err) goto done; - } else { - clean_rootfs(); - unpack_to_rootfs(__initramfs_start, __initramfs_size); - } + + clean_rootfs(); + unpack_to_rootfs(__initramfs_start, __initramfs_size); + printk(KERN_INFO "rootfs image is not initramfs (%s)" "; looks like an initrd\n", err); fd = ksys_open("/initrd.image", @@ -632,7 +631,6 @@ static int __init populate_rootfs(void) written, initrd_end - initrd_start); ksys_close(fd); - free_initrd(); } done: /* empty statement */; @@ -642,9 +640,9 @@ static int __init populate_rootfs(void) initrd_end - initrd_start); if (err) printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); - free_initrd(); #endif } + free_initrd(); flush_delayed_fput(); return 0; } _ Patches currently in -mm which might be from hch@xxxxxx are initramfs-free-initrd-memory-if-opening-initrdimage-fails.patch initramfs-cleanup-initrd-freeing.patch initramfs-factor-out-a-helper-to-populate-the-initrd-image.patch initramfs-cleanup-populate_rootfs.patch initramfs-move-the-legacy-keepinitrd-parameter-to-core-code.patch initramfs-proide-a-generic-free_initrd_mem-implementation.patch initramfs-poison-freed-initrd-memory.patch