diff options
author | Christoph Hellwig <hch@lst.de> | 2019-05-13 20:18:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-05-14 12:47:47 -0400 |
commit | afef7889c480ed134247f16c2ebdeabd75e77fd0 (patch) | |
tree | 8a145d464559dbfba832ec90fe43e3c7ea1be975 | |
parent | 7c184ecd262fe64fe8cf4e099e0f7cefe88d88b2 (diff) |
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>
-rw-r--r-- | init/initramfs.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/init/initramfs.c b/init/initramfs.c index e3de626dbd98..32f940473d67 100644 --- a/init/initramfs.c +++ b/init/initramfs.c | |||
@@ -595,7 +595,11 @@ static void __init clean_rootfs(void) | |||
595 | ksys_close(fd); | 595 | ksys_close(fd); |
596 | kfree(buf); | 596 | kfree(buf); |
597 | } | 597 | } |
598 | #endif | 598 | #else |
599 | static inline void clean_rootfs(void) | ||
600 | { | ||
601 | } | ||
602 | #endif /* CONFIG_BLK_DEV_RAM */ | ||
599 | 603 | ||
600 | #ifdef CONFIG_BLK_DEV_RAM | 604 | #ifdef CONFIG_BLK_DEV_RAM |
601 | static void populate_initrd_image(char *err) | 605 | static void populate_initrd_image(char *err) |
@@ -617,6 +621,11 @@ static void populate_initrd_image(char *err) | |||
617 | written, initrd_end - initrd_start); | 621 | written, initrd_end - initrd_start); |
618 | ksys_close(fd); | 622 | ksys_close(fd); |
619 | } | 623 | } |
624 | #else | ||
625 | static void populate_initrd_image(char *err) | ||
626 | { | ||
627 | printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); | ||
628 | } | ||
620 | #endif /* CONFIG_BLK_DEV_RAM */ | 629 | #endif /* CONFIG_BLK_DEV_RAM */ |
621 | 630 | ||
622 | static int __init populate_rootfs(void) | 631 | static int __init populate_rootfs(void) |
@@ -625,28 +634,22 @@ static int __init populate_rootfs(void) | |||
625 | char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size); | 634 | char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size); |
626 | if (err) | 635 | if (err) |
627 | panic("%s", err); /* Failed to decompress INTERNAL initramfs */ | 636 | panic("%s", err); /* Failed to decompress INTERNAL initramfs */ |
628 | /* If available load the bootloader supplied initrd */ | 637 | |
629 | if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) { | 638 | if (!initrd_start || IS_ENABLED(CONFIG_INITRAMFS_FORCE)) |
630 | #ifdef CONFIG_BLK_DEV_RAM | 639 | goto done; |
640 | |||
641 | if (IS_ENABLED(CONFIG_BLK_DEV_RAM)) | ||
631 | printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); | 642 | printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); |
632 | err = unpack_to_rootfs((char *)initrd_start, | 643 | else |
633 | initrd_end - initrd_start); | 644 | printk(KERN_INFO "Unpacking initramfs...\n"); |
634 | if (!err) | ||
635 | goto done; | ||
636 | 645 | ||
646 | err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start); | ||
647 | if (err) { | ||
637 | clean_rootfs(); | 648 | clean_rootfs(); |
638 | populate_initrd_image(err); | 649 | 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 | ||
648 | } | 650 | } |
649 | 651 | ||
652 | done: | ||
650 | /* | 653 | /* |
651 | * If the initrd region is overlapped with crashkernel reserved region, | 654 | * If the initrd region is overlapped with crashkernel reserved region, |
652 | * free only memory that is not part of crashkernel region. | 655 | * free only memory that is not part of crashkernel region. |