Commit ac6a2b36 authored by Miao Xie's avatar Miao Xie Committed by Chris Mason

Btrfs: fix wrong return value of btrfs_truncate_page()

ret variant may be set to 0 if we read page successfully, but it might be
released before we lock it again. On this case, if we fail to allocate a
new page, we will return 0, it is wrong, fix it.
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 7426cc04
...@@ -3521,11 +3521,11 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len, ...@@ -3521,11 +3521,11 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
if (ret) if (ret)
goto out; goto out;
ret = -ENOMEM;
again: again:
page = find_or_create_page(mapping, index, mask); page = find_or_create_page(mapping, index, mask);
if (!page) { if (!page) {
btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE);
ret = -ENOMEM;
goto out; goto out;
} }
...@@ -3574,7 +3574,6 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len, ...@@ -3574,7 +3574,6 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
goto out_unlock; goto out_unlock;
} }
ret = 0;
if (offset != PAGE_CACHE_SIZE) { if (offset != PAGE_CACHE_SIZE) {
if (!len) if (!len)
len = PAGE_CACHE_SIZE - offset; len = PAGE_CACHE_SIZE - offset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment