linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Engraf <david.engraf@sysgo.com>
To: linux@dominikbrodowski.net, akpm@linux-foundation.org,
	gregkh@linuxfoundation.org, pombredanne@nexb.com, arnd@arndb.de,
	luc.vanoostenryck@gmail.com
Cc: linux-kernel@vger.kernel.org, David Engraf <david.engraf@sysgo.com>
Subject: [PATCH RESEND] initramfs: cleanup incomplete rootfs
Date: Tue, 30 Oct 2018 16:18:05 +0100	[thread overview]
Message-ID: <20181030151805.5519-1-david.engraf@sysgo.com> (raw)
In-Reply-To: <20181022134048.19693-1-david.engraf@sysgo.com>

Unpacking an external initrd may fail e.g. not enough memory. This leads
to an incomplete rootfs because some files might be extracted already.
Fixed by cleaning the rootfs so the kernel is not using an incomplete
rootfs.

Signed-off-by: David Engraf <david.engraf@sysgo.com>
---
 init/initramfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 640557788026..aa3a46cfcb4e 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -548,7 +548,6 @@ static void __init free_initrd(void)
 	initrd_end = 0;
 }
 
-#ifdef CONFIG_BLK_DEV_RAM
 #define BUF_SIZE 1024
 static void __init clean_rootfs(void)
 {
@@ -595,7 +594,6 @@ static void __init clean_rootfs(void)
 	ksys_close(fd);
 	kfree(buf);
 }
-#endif
 
 static int __init populate_rootfs(void)
 {
@@ -638,8 +636,10 @@ static int __init populate_rootfs(void)
 		printk(KERN_INFO "Unpacking initramfs...\n");
 		err = unpack_to_rootfs((char *)initrd_start,
 			initrd_end - initrd_start);
-		if (err)
+		if (err) {
 			printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
+			clean_rootfs();
+		}
 		free_initrd();
 #endif
 	}
-- 
2.17.1


  reply	other threads:[~2018-10-30 15:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-22 13:40 [PATCH] initramfs: cleanup incomplete rootfs David Engraf
2018-10-30 15:18 ` David Engraf [this message]
2019-02-08 19:45   ` [PATCH RESEND] " Andy Shevchenko
2019-02-08 22:08     ` Andrew Morton
2019-02-09 10:35       ` Andy Shevchenko
2019-02-11  7:56         ` David Engraf
2019-02-11  8:49           ` David Engraf
2019-02-11 11:40             ` Andy Shevchenko
2019-02-11 12:40               ` David Engraf
2019-02-12 10:43                 ` Andy Shevchenko
2019-02-12 12:12                   ` David Engraf
2019-02-12 13:50                     ` Andy Shevchenko
2019-02-15 20:13                       ` Andy Shevchenko
2019-02-12  0:56         ` Andrew Morton
2019-02-12  8:04           ` David Engraf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181030151805.5519-1-david.engraf@sysgo.com \
    --to=david.engraf@sysgo.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=pombredanne@nexb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).