ramfs: only change filesize after successful alloc
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
eef551049c
commit
4fff0f4d62
1 changed files with 3 additions and 2 deletions
|
|
@ -113,7 +113,6 @@ static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset)
|
|||
ssize_t ret = 0;
|
||||
if (!inode->data) {
|
||||
inode->data = kalloc(size + offset, ALLOC_KERN);
|
||||
inode->file_size = size + offset;
|
||||
}
|
||||
|
||||
if (!inode->data) {
|
||||
|
|
@ -121,13 +120,15 @@ static ssize_t write(inode_t *inode, char *buf, size_t size, size_t offset)
|
|||
goto out;
|
||||
}
|
||||
|
||||
inode->file_size = size + offset;
|
||||
|
||||
if (inode->file_size < size + offset) {
|
||||
inode->data = krealloc(inode->data, size + offset, ALLOC_KERN);
|
||||
inode->file_size = size + offset;
|
||||
if (!inode->data) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
inode->file_size = size + offset;
|
||||
}
|
||||
|
||||
memcpy(inode->data + offset, buf, size);
|
||||
|
|
|
|||
Loading…
Reference in a new issue