Commit b7ea89ad authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: allow a NULL argument to ext4_ext_drop_refs()

Teach ext4_ext_drop_refs() to accept a NULL argument, much like
kfree().  This allows us to drop a lot of checks to make sure path is
non-NULL before calling ext4_ext_drop_refs().
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 523f431c
...@@ -709,9 +709,11 @@ static void ext4_ext_show_move(struct inode *inode, struct ext4_ext_path *path, ...@@ -709,9 +709,11 @@ static void ext4_ext_show_move(struct inode *inode, struct ext4_ext_path *path,
void ext4_ext_drop_refs(struct ext4_ext_path *path) void ext4_ext_drop_refs(struct ext4_ext_path *path)
{ {
int depth = path->p_depth; int depth, i;
int i;
if (!path)
return;
depth = path->p_depth;
for (i = 0; i <= depth; i++, path++) for (i = 0; i <= depth; i++, path++)
if (path->p_bh) { if (path->p_bh) {
brelse(path->p_bh); brelse(path->p_bh);
...@@ -2125,10 +2127,8 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, ...@@ -2125,10 +2127,8 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
err = ext4_ext_dirty(handle, inode, path + path->p_depth); err = ext4_ext_dirty(handle, inode, path + path->p_depth);
cleanup: cleanup:
if (npath) { ext4_ext_drop_refs(npath);
ext4_ext_drop_refs(npath); kfree(npath);
kfree(npath);
}
return err; return err;
} }
...@@ -2283,11 +2283,8 @@ static int ext4_fill_fiemap_extents(struct inode *inode, ...@@ -2283,11 +2283,8 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
block = es.es_lblk + es.es_len; block = es.es_lblk + es.es_len;
} }
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path);
}
return err; return err;
} }
...@@ -3018,11 +3015,9 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, ...@@ -3018,11 +3015,9 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
} }
} }
out: out:
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path); path = NULL;
path = NULL;
}
if (err == -EAGAIN) if (err == -EAGAIN)
goto again; goto again;
ext4_journal_stop(handle); ext4_journal_stop(handle);
...@@ -4611,10 +4606,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, ...@@ -4611,10 +4606,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
map->m_pblk = newblock; map->m_pblk = newblock;
map->m_len = allocated; map->m_len = allocated;
out2: out2:
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path);
}
trace_ext4_ext_map_blocks_exit(inode, flags, map, trace_ext4_ext_map_blocks_exit(inode, flags, map,
err ? err : allocated); err ? err : allocated);
...@@ -5693,16 +5686,11 @@ ext4_swap_extents(handle_t *handle, struct inode *inode1, ...@@ -5693,16 +5686,11 @@ ext4_swap_extents(handle_t *handle, struct inode *inode1,
count -= len; count -= len;
repeat: repeat:
if (path1) { ext4_ext_drop_refs(path1);
ext4_ext_drop_refs(path1); kfree(path1);
kfree(path1); ext4_ext_drop_refs(path2);
path1 = NULL; kfree(path2);
} path1 = path2 = NULL;
if (path2) {
ext4_ext_drop_refs(path2);
kfree(path2);
path2 = NULL;
}
} }
return replaced_count; return replaced_count;
} }
...@@ -499,10 +499,8 @@ static void ext4_es_insert_extent_ext_check(struct inode *inode, ...@@ -499,10 +499,8 @@ static void ext4_es_insert_extent_ext_check(struct inode *inode,
} }
} }
out: out:
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path);
}
} }
static void ext4_es_insert_extent_ind_check(struct inode *inode, static void ext4_es_insert_extent_ind_check(struct inode *inode,
......
...@@ -84,10 +84,8 @@ static int finish_range(handle_t *handle, struct inode *inode, ...@@ -84,10 +84,8 @@ static int finish_range(handle_t *handle, struct inode *inode,
retval = ext4_ext_insert_extent(handle, inode, &path, &newext, 0); retval = ext4_ext_insert_extent(handle, inode, &path, &newext, 0);
err_out: err_out:
up_write((&EXT4_I(inode)->i_data_sem)); up_write((&EXT4_I(inode)->i_data_sem));
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path);
}
lb->first_pblock = 0; lb->first_pblock = 0;
return retval; return retval;
} }
......
...@@ -113,10 +113,8 @@ mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count, ...@@ -113,10 +113,8 @@ mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count,
} }
ret = 1; ret = 1;
out: out:
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path);
}
return ret; return ret;
} }
...@@ -711,11 +709,9 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, ...@@ -711,11 +709,9 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
o_start += cur_len; o_start += cur_len;
d_start += cur_len; d_start += cur_len;
repeat: repeat:
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path); path = NULL;
path = NULL;
}
} }
*moved_len = o_start - orig_blk; *moved_len = o_start - orig_blk;
if (*moved_len > len) if (*moved_len > len)
...@@ -727,10 +723,8 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, ...@@ -727,10 +723,8 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
ext4_discard_preallocations(donor_inode); ext4_discard_preallocations(donor_inode);
} }
if (path) { ext4_ext_drop_refs(path);
ext4_ext_drop_refs(path); kfree(path);
kfree(path);
}
ext4_double_up_write_data_sem(orig_inode, donor_inode); ext4_double_up_write_data_sem(orig_inode, donor_inode);
ext4_inode_resume_unlocked_dio(orig_inode); ext4_inode_resume_unlocked_dio(orig_inode);
ext4_inode_resume_unlocked_dio(donor_inode); ext4_inode_resume_unlocked_dio(donor_inode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment