Skip to content

Commit b860545

Browse files
osandovmasoncl
authored andcommitted
btrfs: check io_ctl_prepare_pages return in __btrfs_write_out_cache
If io_ctl_prepare_pages fails, the pages in io_ctl.pages are not valid. When we try to access them later, things will blow up in various ways. Also fix the comment about the return value, which is an errno on error, not -1, and update the cases where it was not. Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Omar Sandoval <osandov@osandov.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 5ca64f4 commit b860545

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fs/btrfs/free-space-cache.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ int btrfs_wait_cache_io(struct btrfs_root *root,
12181218
*
12191219
* This function writes out a free space cache struct to disk for quick recovery
12201220
* on mount. This will return 0 if it was successfull in writing the cache out,
1221-
* and -1 if it was not.
1221+
* or an errno if it was not.
12221222
*/
12231223
static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
12241224
struct btrfs_free_space_ctl *ctl,
@@ -1235,12 +1235,12 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
12351235
int must_iput = 0;
12361236

12371237
if (!i_size_read(inode))
1238-
return -1;
1238+
return -EIO;
12391239

12401240
WARN_ON(io_ctl->pages);
12411241
ret = io_ctl_init(io_ctl, inode, root, 1);
12421242
if (ret)
1243-
return -1;
1243+
return ret;
12441244

12451245
if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) {
12461246
down_write(&block_group->data_rwsem);
@@ -1258,7 +1258,9 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
12581258
}
12591259

12601260
/* Lock all pages first so we can lock the extent safely. */
1261-
io_ctl_prepare_pages(io_ctl, inode, 0);
1261+
ret = io_ctl_prepare_pages(io_ctl, inode, 0);
1262+
if (ret)
1263+
goto out;
12621264

12631265
lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1,
12641266
0, &cached_state);

0 commit comments

Comments
 (0)