]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.51/initramfs-free-initrd-memory-if-opening-initrd.image.patch
Linux 5.1.10
[thirdparty/kernel/stable-queue.git] / releases / 4.19.51 / initramfs-free-initrd-memory-if-opening-initrd.image.patch
1 From 92fcf9ecaac922281743603a8a8c336927022bfd Mon Sep 17 00:00:00 2001
2 From: Christoph Hellwig <hch@lst.de>
3 Date: Mon, 13 May 2019 17:18:17 -0700
4 Subject: initramfs: free initrd memory if opening /initrd.image fails
5
6 [ Upstream commit 54c7a8916a887f357088f99e9c3a7720cd57d2c8 ]
7
8 Patch series "initramfs tidyups".
9
10 I've spent some time chasing down behavior in initramfs and found
11 plenty of opportunity to improve the code. A first stab on that is
12 contained in this series.
13
14 This patch (of 7):
15
16 We free the initrd memory for all successful or error cases except for the
17 case where opening /initrd.image fails, which looks like an oversight.
18
19 Steven said:
20
21 : This also changes the behaviour when CONFIG_INITRAMFS_FORCE is enabled
22 : - specifically it means that the initrd is freed (previously it was
23 : ignored and never freed). But that seems like reasonable behaviour and
24 : the previous behaviour looks like another oversight.
25
26 Link: http://lkml.kernel.org/r/20190213174621.29297-3-hch@lst.de
27 Signed-off-by: Christoph Hellwig <hch@lst.de>
28 Reviewed-by: Steven Price <steven.price@arm.com>
29 Acked-by: Mike Rapoport <rppt@linux.ibm.com>
30 Cc: Catalin Marinas <catalin.marinas@arm.com> [arm64]
31 Cc: Geert Uytterhoeven <geert@linux-m68k.org> [m68k]
32 Cc: Alexander Viro <viro@zeniv.linux.org.uk>
33 Cc: Russell King <linux@armlinux.org.uk>
34 Cc: Will Deacon <will.deacon@arm.com>
35 Cc: Guan Xuetao <gxt@pku.edu.cn>
36 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
37 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
38 Signed-off-by: Sasha Levin <sashal@kernel.org>
39 ---
40 init/initramfs.c | 14 ++++++--------
41 1 file changed, 6 insertions(+), 8 deletions(-)
42
43 diff --git a/init/initramfs.c b/init/initramfs.c
44 index f6f4a1e4cd54..cd5fb00fcb54 100644
45 --- a/init/initramfs.c
46 +++ b/init/initramfs.c
47 @@ -612,13 +612,12 @@ static int __init populate_rootfs(void)
48 printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
49 err = unpack_to_rootfs((char *)initrd_start,
50 initrd_end - initrd_start);
51 - if (!err) {
52 - free_initrd();
53 + if (!err)
54 goto done;
55 - } else {
56 - clean_rootfs();
57 - unpack_to_rootfs(__initramfs_start, __initramfs_size);
58 - }
59 +
60 + clean_rootfs();
61 + unpack_to_rootfs(__initramfs_start, __initramfs_size);
62 +
63 printk(KERN_INFO "rootfs image is not initramfs (%s)"
64 "; looks like an initrd\n", err);
65 fd = ksys_open("/initrd.image",
66 @@ -632,7 +631,6 @@ static int __init populate_rootfs(void)
67 written, initrd_end - initrd_start);
68
69 ksys_close(fd);
70 - free_initrd();
71 }
72 done:
73 /* empty statement */;
74 @@ -642,9 +640,9 @@ static int __init populate_rootfs(void)
75 initrd_end - initrd_start);
76 if (err)
77 printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
78 - free_initrd();
79 #endif
80 }
81 + free_initrd();
82 flush_delayed_fput();
83 /*
84 * Try loading default modules from initramfs. This gives
85 --
86 2.20.1
87