In btrfs_destroy_inode(), the variable root may be NULL, but the check for this takes place after its value has already been dereferenced to access its fs_info member. Move the dereference operation to later in the function.
Fixes: a6dbd429d8dd ("Btrfs: fix panic when trying to destroy a newly allocated") Addresses-Coverity: CID 1497103: Null pointer dereferences (REVERSE_INULL) Signed-off-by: Alex Dewar <a.de...@sussex.ac.uk> --- fs/btrfs/inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a5dae53c1e27..8f230b7bfe65 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8648,7 +8648,6 @@ void btrfs_destroy_inode(struct inode *vfs_inode) struct btrfs_ordered_extent *ordered; struct btrfs_inode *inode = BTRFS_I(vfs_inode); struct btrfs_root *root = inode->root; - struct btrfs_fs_info *fs_info = root->fs_info; WARN_ON(!hlist_empty(&vfs_inode->i_dentry)); WARN_ON(vfs_inode->i_data.nrpages); @@ -8673,7 +8672,7 @@ void btrfs_destroy_inode(struct inode *vfs_inode) if (!ordered) break; else { - btrfs_err(fs_info, + btrfs_err(root->fs_info, "found ordered extent %llu %llu on inode cleanup", ordered->file_offset, ordered->num_bytes); btrfs_remove_ordered_extent(inode, ordered); -- 2.28.0