Skip to content

Commit

Permalink
initramfs: cleanup populate_rootfs
Browse files Browse the repository at this point in the history
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.

[[email protected]: fix a compilation error]
  Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Qian Cai <[email protected]>
Acked-by: Mike Rapoport <[email protected]>
Cc: Catalin Marinas <[email protected]>	[arm64]
Cc: Geert Uytterhoeven <[email protected]>	[m68k]
Cc: Steven Price <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Russell King <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Christoph Hellwig authored and torvalds committed May 14, 2019
1 parent 7c184ec commit afef788
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit afef788

Please sign in to comment.