Skip to content

Commit afef788

Browse files
Christoph Hellwigtorvalds
authored andcommitted
initramfs: cleanup populate_rootfs
The code for kernels that support ramdisks or not is mostly the same. Unify it by using an IS_ENABLED for the info message, and moving the error message into a stub for populate_initrd_image. [cai@lca.pw: fix a compilation error] Link: http://lkml.kernel.org/r/20190328014806.36375-1-cai@lca.pw Link: http://lkml.kernel.org/r/20190213174621.29297-6-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Qian Cai <cai@lca.pw> 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>
1 parent 7c184ec commit afef788

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

‎init/initramfs.c‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,11 @@ static void __init clean_rootfs(void)
595595
ksys_close(fd);
596596
kfree(buf);
597597
}
598-
#endif
598+
#else
599+
static inline void clean_rootfs(void)
600+
{
601+
}
602+
#endif /* CONFIG_BLK_DEV_RAM */
599603

600604
#ifdef CONFIG_BLK_DEV_RAM
601605
static void populate_initrd_image(char *err)
@@ -617,6 +621,11 @@ static void populate_initrd_image(char *err)
617621
written, initrd_end - initrd_start);
618622
ksys_close(fd);
619623
}
624+
#else
625+
static void populate_initrd_image(char *err)
626+
{
627+
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
628+
}
620629
#endif /* CONFIG_BLK_DEV_RAM */
621630

622631
static int __init populate_rootfs(void)
@@ -625,28 +634,22 @@ static int __init populate_rootfs(void)
625634
char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
626635
if (err)
627636
panic("%s", err); /* Failed to decompress INTERNAL initramfs */
628-
/* If available load the bootloader supplied initrd */
629-
if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) {
630-
#ifdef CONFIG_BLK_DEV_RAM
637+
638+
if (!initrd_start || IS_ENABLED(CONFIG_INITRAMFS_FORCE))
639+
goto done;
640+
641+
if (IS_ENABLED(CONFIG_BLK_DEV_RAM))
631642
printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
632-
err = unpack_to_rootfs((char *)initrd_start,
633-
initrd_end - initrd_start);
634-
if (!err)
635-
goto done;
643+
else
644+
printk(KERN_INFO "Unpacking initramfs...\n");
636645

646+
err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start);
647+
if (err) {
637648
clean_rootfs();
638649
populate_initrd_image(err);
639-
done:
640-
/* empty statement */;
641-
#else
642-
printk(KERN_INFO "Unpacking initramfs...\n");
643-
err = unpack_to_rootfs((char *)initrd_start,
644-
initrd_end - initrd_start);
645-
if (err)
646-
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
647-
#endif
648650
}
649651

652+
done:
650653
/*
651654
* If the initrd region is overlapped with crashkernel reserved region,
652655
* free only memory that is not part of crashkernel region.

0 commit comments

Comments
 (0)