initramfs: cleanup populate_rootfs
authorChristoph Hellwig <hch@lst.de>
Tue, 14 May 2019 00:18:27 +0000 (17:18 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 May 2019 16:47:47 +0000 (09:47 -0700)
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>
init/initramfs.c

index e3de626dbd98edcc154569ecc0666233901ba269..32f940473d6768c8191df1b02e91cac33adaa3bb 100644 (file)
@@ -595,7 +595,11 @@ static void __init clean_rootfs(void)
        ksys_close(fd);
        kfree(buf);
 }
-#endif
+#else
+static inline void clean_rootfs(void)
+{
+}
+#endif /* CONFIG_BLK_DEV_RAM */
 
 #ifdef CONFIG_BLK_DEV_RAM
 static void populate_initrd_image(char *err)
@@ -617,6 +621,11 @@ static void populate_initrd_image(char *err)
                       written, initrd_end - initrd_start);
        ksys_close(fd);
 }
+#else
+static void populate_initrd_image(char *err)
+{
+       printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
+}
 #endif /* CONFIG_BLK_DEV_RAM */
 
 static int __init populate_rootfs(void)
@@ -625,28 +634,22 @@ static int __init populate_rootfs(void)
        char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
        if (err)
                panic("%s", err); /* Failed to decompress INTERNAL initramfs */
-       /* If available load the bootloader supplied initrd */
-       if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) {
-#ifdef CONFIG_BLK_DEV_RAM
+
+       if (!initrd_start || IS_ENABLED(CONFIG_INITRAMFS_FORCE))
+               goto done;
+
+       if (IS_ENABLED(CONFIG_BLK_DEV_RAM))
                printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
-               err = unpack_to_rootfs((char *)initrd_start,
-                       initrd_end - initrd_start);
-               if (!err)
-                       goto done;
+       else
+               printk(KERN_INFO "Unpacking initramfs...\n");
 
+       err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start);
+       if (err) {
                clean_rootfs();
                populate_initrd_image(err);
-       done:
-               /* empty statement */;
-#else
-               printk(KERN_INFO "Unpacking initramfs...\n");
-               err = unpack_to_rootfs((char *)initrd_start,
-                       initrd_end - initrd_start);
-               if (err)
-                       printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
-#endif
        }
 
+done:
        /*
         * If the initrd region is overlapped with crashkernel reserved region,
         * free only memory that is not part of crashkernel region.