@@ -869,14 +869,20 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
869
869
eh = ext_inode_hdr (inode );
870
870
depth = ext_depth (inode );
871
871
872
- if (path )
872
+ if (path ) {
873
873
ext4_ext_drop_refs (path );
874
- else {
874
+ if (depth > path [0 ].p_maxdepth ) {
875
+ kfree (path );
876
+ * orig_path = path = NULL ;
877
+ }
878
+ }
879
+ if (!path ) {
875
880
/* account possible depth increase */
876
881
path = kzalloc (sizeof (struct ext4_ext_path ) * (depth + 2 ),
877
882
GFP_NOFS );
878
883
if (unlikely (!path ))
879
884
return ERR_PTR (- ENOMEM );
885
+ path [0 ].p_maxdepth = depth + 1 ;
880
886
}
881
887
path [0 ].p_hdr = eh ;
882
888
path [0 ].p_bh = NULL ;
@@ -1820,6 +1826,7 @@ static void ext4_ext_try_to_merge_up(handle_t *handle,
1820
1826
sizeof (struct ext4_extent_idx );
1821
1827
s += sizeof (struct ext4_extent_header );
1822
1828
1829
+ path [1 ].p_maxdepth = path [0 ].p_maxdepth ;
1823
1830
memcpy (path [0 ].p_hdr , path [1 ].p_hdr , s );
1824
1831
path [0 ].p_depth = 0 ;
1825
1832
path [0 ].p_ext = EXT_FIRST_EXTENT (path [0 ].p_hdr ) +
@@ -2150,12 +2157,6 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
2150
2157
/* find extent for this block */
2151
2158
down_read (& EXT4_I (inode )-> i_data_sem );
2152
2159
2153
- if (path && ext_depth (inode ) != depth ) {
2154
- /* depth was changed. we have to realloc path */
2155
- kfree (path );
2156
- path = NULL ;
2157
- }
2158
-
2159
2160
path = ext4_ext_find_extent (inode , block , & path , 0 );
2160
2161
if (IS_ERR (path )) {
2161
2162
up_read (& EXT4_I (inode )-> i_data_sem );
@@ -2173,7 +2174,6 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
2173
2174
}
2174
2175
ex = path [depth ].p_ext ;
2175
2176
next = ext4_ext_next_allocated_block (path );
2176
- ext4_ext_drop_refs (path );
2177
2177
2178
2178
flags = 0 ;
2179
2179
exists = 0 ;
@@ -2897,7 +2897,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
2897
2897
ext4_journal_stop (handle );
2898
2898
return - ENOMEM ;
2899
2899
}
2900
- path [0 ].p_depth = depth ;
2900
+ path [0 ].p_maxdepth = path [ 0 ]. p_depth = depth ;
2901
2901
path [0 ].p_hdr = ext_inode_hdr (inode );
2902
2902
i = 0 ;
2903
2903
0 commit comments