* [PATCH] btrfs: don't leak extent_map in btrfs_get_io_geometry()
@ 2019-07-15 13:16 Johannes Thumshirn
2019-07-15 13:22 ` Nikolay Borisov
2019-07-17 14:58 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2019-07-15 13:16 UTC (permalink / raw)
To: David Sterba; +Cc: Nikolay Borisov, Linux BTRFS Mailinglist, Johannes Thumshirn
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: 5f1411265e16 ("btrfs: Introduce btrfs_io_geometry infrastructure")
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
fs/btrfs/volumes.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a13ddba1ebc3..d74b74ca07af 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5941,6 +5941,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
u64 stripe_len;
u64 raid56_full_stripe_start = (u64)-1;
int data_stripes;
+ int ret = 0;
ASSERT(op != BTRFS_MAP_DISCARD);
@@ -5961,8 +5962,8 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
btrfs_crit(fs_info,
"stripe math has gone wrong, stripe_offset=%llu offset=%llu start=%llu logical=%llu stripe_len=%llu",
stripe_offset, offset, em->start, logical, stripe_len);
- free_extent_map(em);
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
/* 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,
io_geom->stripe_offset = stripe_offset;
io_geom->raid56_stripe_offset = raid56_full_stripe_start;
- return 0;
+out:
+ /* once for us */
+ free_extent_map(em);
+ return ret;
}
static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
--
2.16.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: don't leak extent_map in btrfs_get_io_geometry()
2019-07-15 13:16 [PATCH] btrfs: don't leak extent_map in btrfs_get_io_geometry() Johannes Thumshirn
@ 2019-07-15 13:22 ` Nikolay Borisov
2019-07-17 14:58 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2019-07-15 13:22 UTC (permalink / raw)
To: Johannes Thumshirn, David Sterba; +Cc: Linux BTRFS Mailinglist
On 15.07.19 г. 16:16 ч., Johannes Thumshirn wrote:
> 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: 5f1411265e16 ("btrfs: Introduce btrfs_io_geometry infrastructure")
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
My bad:
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/volumes.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index a13ddba1ebc3..d74b74ca07af 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5941,6 +5941,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
> u64 stripe_len;
> u64 raid56_full_stripe_start = (u64)-1;
> int data_stripes;
> + int ret = 0;
>
> ASSERT(op != BTRFS_MAP_DISCARD);
>
> @@ -5961,8 +5962,8 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
> btrfs_crit(fs_info,
> "stripe math has gone wrong, stripe_offset=%llu offset=%llu start=%llu logical=%llu stripe_len=%llu",
> stripe_offset, offset, em->start, logical, stripe_len);
> - free_extent_map(em);
> - return -EINVAL;
> + ret = -EINVAL;
> + goto out;
> }
>
> /* 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,
> io_geom->stripe_offset = stripe_offset;
> io_geom->raid56_stripe_offset = raid56_full_stripe_start;
>
> - return 0;
> +out:
> + /* once for us */
> + free_extent_map(em);
> + return ret;
> }
>
> static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: don't leak extent_map in btrfs_get_io_geometry()
2019-07-15 13:16 [PATCH] btrfs: don't leak extent_map in btrfs_get_io_geometry() Johannes Thumshirn
2019-07-15 13:22 ` Nikolay Borisov
@ 2019-07-17 14:58 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2019-07-17 14:58 UTC (permalink / raw)
To: Johannes Thumshirn; +Cc: David Sterba, Nikolay Borisov, Linux BTRFS Mailinglist
On Mon, Jul 15, 2019 at 03:16:12PM +0200, Johannes Thumshirn wrote:
> 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: 5f1411265e16 ("btrfs: Introduce btrfs_io_geometry infrastructure")
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Added to 5.3 queue, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-17 14:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15 13:16 [PATCH] btrfs: don't leak extent_map in btrfs_get_io_geometry() Johannes Thumshirn
2019-07-15 13:22 ` Nikolay Borisov
2019-07-17 14:58 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.