Skip to content

Commit

Permalink
Btrfs: fix wrong return value of btrfs_truncate_page()
Browse files Browse the repository at this point in the history
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: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
  • Loading branch information
Miao Xie authored and Chris Mason committed Dec 17, 2012
1 parent 7426cc0 commit ac6a2b3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3521,11 +3521,11 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
if (ret)
goto out;

ret = -ENOMEM;
again:
page = find_or_create_page(mapping, index, mask);
if (!page) {
btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE);
ret = -ENOMEM;
goto out;
}

Expand Down Expand Up @@ -3574,7 +3574,6 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
goto out_unlock;
}

ret = 0;
if (offset != PAGE_CACHE_SIZE) {
if (!len)
len = PAGE_CACHE_SIZE - offset;
Expand Down

0 comments on commit ac6a2b3

Please sign in to comment.