ext4: use IS_ERR instead of IS_ERR_OR_NULL and set inode null when IS_ERR
authorYi Li <yili@winhong.com>
Wed, 30 Dec 2020 03:38:27 +0000 (11:38 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:27:19 +0000 (18:27 +0100)
commit 23dd561ad9eae02b4d51bb502fe4e1a0666e9567 upstream.

1: ext4_iget/ext4_find_extent never returns NULL, use IS_ERR
instead of IS_ERR_OR_NULL to fix this.

2: ext4_fc_replay_inode should set the inode to NULL when IS_ERR.
and go to call iput properly.

Fixes: 8016e29f4362 ("ext4: fast commit recovery path")
Signed-off-by: Yi Li <yili@winhong.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20201230033827.3996064-1-yili@winhong.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/fast_commit.c

index f2033e1..cc19c5c 100644 (file)
@@ -1269,14 +1269,14 @@ static int ext4_fc_replay_unlink(struct super_block *sb, struct ext4_fc_tl *tl)
        entry.len = darg.dname_len;
        inode = ext4_iget(sb, darg.ino, EXT4_IGET_NORMAL);
 
-       if (IS_ERR_OR_NULL(inode)) {
+       if (IS_ERR(inode)) {
                jbd_debug(1, "Inode %d not found", darg.ino);
                return 0;
        }
 
        old_parent = ext4_iget(sb, darg.parent_ino,
                                EXT4_IGET_NORMAL);
-       if (IS_ERR_OR_NULL(old_parent)) {
+       if (IS_ERR(old_parent)) {
                jbd_debug(1, "Dir with inode  %d not found", darg.parent_ino);
                iput(inode);
                return 0;
@@ -1361,7 +1361,7 @@ static int ext4_fc_replay_link(struct super_block *sb, struct ext4_fc_tl *tl)
                        darg.parent_ino, darg.dname_len);
 
        inode = ext4_iget(sb, darg.ino, EXT4_IGET_NORMAL);
-       if (IS_ERR_OR_NULL(inode)) {
+       if (IS_ERR(inode)) {
                jbd_debug(1, "Inode not found.");
                return 0;
        }
@@ -1417,10 +1417,11 @@ static int ext4_fc_replay_inode(struct super_block *sb, struct ext4_fc_tl *tl)
        trace_ext4_fc_replay(sb, tag, ino, 0, 0);
 
        inode = ext4_iget(sb, ino, EXT4_IGET_NORMAL);
-       if (!IS_ERR_OR_NULL(inode)) {
+       if (!IS_ERR(inode)) {
                ext4_ext_clear_bb(inode);
                iput(inode);
        }
+       inode = NULL;
 
        ext4_fc_record_modified_inode(sb, ino);
 
@@ -1463,7 +1464,7 @@ static int ext4_fc_replay_inode(struct super_block *sb, struct ext4_fc_tl *tl)
 
        /* Given that we just wrote the inode on disk, this SHOULD succeed. */
        inode = ext4_iget(sb, ino, EXT4_IGET_NORMAL);
-       if (IS_ERR_OR_NULL(inode)) {
+       if (IS_ERR(inode)) {
                jbd_debug(1, "Inode not found.");
                return -EFSCORRUPTED;
        }
@@ -1515,7 +1516,7 @@ static int ext4_fc_replay_create(struct super_block *sb, struct ext4_fc_tl *tl)
                goto out;
 
        inode = ext4_iget(sb, darg.ino, EXT4_IGET_NORMAL);
-       if (IS_ERR_OR_NULL(inode)) {
+       if (IS_ERR(inode)) {
                jbd_debug(1, "inode %d not found.", darg.ino);
                inode = NULL;
                ret = -EINVAL;
@@ -1528,7 +1529,7 @@ static int ext4_fc_replay_create(struct super_block *sb, struct ext4_fc_tl *tl)
                 * dot and dot dot dirents are setup properly.
                 */
                dir = ext4_iget(sb, darg.parent_ino, EXT4_IGET_NORMAL);
-               if (IS_ERR_OR_NULL(dir)) {
+               if (IS_ERR(dir)) {
                        jbd_debug(1, "Dir %d not found.", darg.ino);
                        goto out;
                }
@@ -1604,7 +1605,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
 
        inode = ext4_iget(sb, le32_to_cpu(fc_add_ex->fc_ino),
                                EXT4_IGET_NORMAL);
-       if (IS_ERR_OR_NULL(inode)) {
+       if (IS_ERR(inode)) {
                jbd_debug(1, "Inode not found.");
                return 0;
        }
@@ -1728,7 +1729,7 @@ ext4_fc_replay_del_range(struct super_block *sb, struct ext4_fc_tl *tl)
                le32_to_cpu(lrange->fc_ino), cur, remaining);
 
        inode = ext4_iget(sb, le32_to_cpu(lrange->fc_ino), EXT4_IGET_NORMAL);
-       if (IS_ERR_OR_NULL(inode)) {
+       if (IS_ERR(inode)) {
                jbd_debug(1, "Inode %d not found", le32_to_cpu(lrange->fc_ino));
                return 0;
        }
@@ -1809,7 +1810,7 @@ static void ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
        for (i = 0; i < state->fc_modified_inodes_used; i++) {
                inode = ext4_iget(sb, state->fc_modified_inodes[i],
                        EXT4_IGET_NORMAL);
-               if (IS_ERR_OR_NULL(inode)) {
+               if (IS_ERR(inode)) {
                        jbd_debug(1, "Inode %d not found.",
                                state->fc_modified_inodes[i]);
                        continue;
@@ -1826,7 +1827,7 @@ static void ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
 
                        if (ret > 0) {
                                path = ext4_find_extent(inode, map.m_lblk, NULL, 0);
-                               if (!IS_ERR_OR_NULL(path)) {
+                               if (!IS_ERR(path)) {
                                        for (j = 0; j < path->p_depth; j++)
                                                ext4_mb_mark_bb(inode->i_sb,
                                                        path[j].p_block, 1, 1);