@@ -286,8 +286,14 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode,
if (!io_ctl->pages)
return -ENOMEM;
io_ctl->root = root;
- if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID)
+ if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) {
io_ctl->check_crcs = 1;
+ if ((io_ctl.num_pages * sizeof(u32)) >
+ (PAGE_CACHE_SIZE - sizeof(u64) * 2)) {
+ WARN_ON(1);
+ return -1;
+ }
+ }
return 0;
}
@@ -917,7 +923,8 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
/* Make sure we can fit our crcs into the first page */
if (io_ctl.check_crcs &&
- (io_ctl.num_pages * sizeof(u32)) >= PAGE_CACHE_SIZE) {
+ (io_ctl.num_pages * sizeof(u32)) >
+ (PAGE_CACHE_SIZE - sizeof(u64) * 2)) {
WARN_ON(1);
goto out_nospc;
}