]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
initramfs: add write error checks
authorDavid Engraf <david.engraf@sysgo.com>
Fri, 8 Aug 2014 21:23:16 +0000 (14:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 8 Aug 2014 22:57:26 +0000 (15:57 -0700)
On a system with low memory extracting the initramfs may fail.  If this
happens the user gets "Failed to execute /init" instead of an initramfs
error.

Check return value of sys_write and call error() when the write was
incomplete or failed.

Signed-off-by: David Engraf <david.engraf@sysgo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
init/initramfs.c

index a7566031242e56cb0076174966c91a523fc253b6..bece48c3461edd55ba4a9ea5fc1b8662be6bda0f 100644 (file)
@@ -369,7 +369,8 @@ static int __init do_name(void)
 static int __init do_copy(void)
 {
        if (count >= body_len) {
-               xwrite(wfd, victim, body_len);
+               if (xwrite(wfd, victim, body_len) != body_len)
+                       error("write error");
                sys_close(wfd);
                do_utime(vcollected, mtime);
                kfree(vcollected);
@@ -377,7 +378,8 @@ static int __init do_copy(void)
                state = SkipIt;
                return 0;
        } else {
-               xwrite(wfd, victim, count);
+               if (xwrite(wfd, victim, count) != count)
+                       error("write error");
                body_len -= count;
                eat(count);
                return 1;