Skip to content

Commit 917c16b

Browse files
committed
Btrfs: fix oops on NULL trans handle in btrfs_truncate
If we fail to reserve space in the transaction during truncate, we can error out with a NULL trans handle. The cleanup code needs an extra check to make sure we aren't trying to use the bad handle. Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 45ea609 commit 917c16b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎fs/btrfs/inode.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6529,14 +6529,16 @@ static int btrfs_truncate(struct inode *inode)
65296529
ret = btrfs_orphan_del(NULL, inode);
65306530
}
65316531

6532-
trans->block_rsv = &root->fs_info->trans_block_rsv;
6533-
ret = btrfs_update_inode(trans, root, inode);
6534-
if (ret && !err)
6535-
err = ret;
6532+
if (trans) {
6533+
trans->block_rsv = &root->fs_info->trans_block_rsv;
6534+
ret = btrfs_update_inode(trans, root, inode);
6535+
if (ret && !err)
6536+
err = ret;
65366537

6537-
nr = trans->blocks_used;
6538-
ret = btrfs_end_transaction_throttle(trans, root);
6539-
btrfs_btree_balance_dirty(root, nr);
6538+
nr = trans->blocks_used;
6539+
ret = btrfs_end_transaction_throttle(trans, root);
6540+
btrfs_btree_balance_dirty(root, nr);
6541+
}
65406542

65416543
out:
65426544
btrfs_free_block_rsv(root, rsv);

0 commit comments

Comments
 (0)