initramfs: add write error checks

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>
This commit is contained in:
David Engraf 2014-08-08 14:23:16 -07:00 committed by Linus Torvalds
parent d97b07c54f
commit 9687fd9101
1 changed files with 4 additions and 2 deletions

View File

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