Skip to content

Commit 373c3b8

Browse files
Johannes Thumshirnkdave
authored andcommitted
btrfs: don't leak extent_map in btrfs_get_io_geometry()
btrfs_get_io_geometry() calls btrfs_get_chunk_map() to acquire a reference on a extent_map, but on normal operation it does not drop this reference anymore. This leads to excessive kmemleak reports. Always call free_extent_map(), not just in the error case. Fixes: 5f14112 ("btrfs: Introduce btrfs_io_geometry infrastructure") Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent bfcea1c commit 373c3b8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/btrfs/volumes.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5941,6 +5941,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
59415941
u64 stripe_len;
59425942
u64 raid56_full_stripe_start = (u64)-1;
59435943
int data_stripes;
5944+
int ret = 0;
59445945

59455946
ASSERT(op != BTRFS_MAP_DISCARD);
59465947

@@ -5961,8 +5962,8 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
59615962
btrfs_crit(fs_info,
59625963
"stripe math has gone wrong, stripe_offset=%llu offset=%llu start=%llu logical=%llu stripe_len=%llu",
59635964
stripe_offset, offset, em->start, logical, stripe_len);
5964-
free_extent_map(em);
5965-
return -EINVAL;
5965+
ret = -EINVAL;
5966+
goto out;
59665967
}
59675968

59685969
/* stripe_offset is the offset of this block in its stripe */
@@ -6009,7 +6010,10 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
60096010
io_geom->stripe_offset = stripe_offset;
60106011
io_geom->raid56_stripe_offset = raid56_full_stripe_start;
60116012

6012-
return 0;
6013+
out:
6014+
/* once for us */
6015+
free_extent_map(em);
6016+
return ret;
60136017
}
60146018

60156019
static int __btrfs_map_block(struct btrfs_fs_info *fs_info,

0 commit comments

Comments
 (0)