We should check the inode validation before checking the imode.
As btrfs_iget() could return ERR_PTR(), unlike previous path, we need to
verify the inode before checking the imode.
Signed-off-by: Qu Wenruo <wqu@xxxxxxxx>
---
To David:
Please fold this into 9944a5b5d26e ("btrfs: inode: Verify inode mode to avoid NULL pointer dereference")
of misc-next branch.
---
fs/btrfs/inode.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3ee835cbb490..97f47dd295e8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5776,6 +5776,8 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
if (location.type == BTRFS_INODE_ITEM_KEY) {
inode = btrfs_iget(dir->i_sb, &location, root, NULL);
+ if (IS_ERR(inode))
+ return inode;
/* Do extra check against inode mode with di_type */
if (btrfs_inode_type(inode) != di_type) {
--
2.21.0