mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
btrfs: fix copy_remapped_data() to not allocate more memory than intended
The loop intends to copy the data in chunks up to 1M but we allocate the pages array for the entire length and don't cap it to 1M. Fix this by computing 'nr_pages' using 'copy_len' instead of 'length'. While at it, also make 'nr_pages' and 'copy_len' const, as they never change, to make the code more clear. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
6f1c97695a
commit
0a9c35d304
|
|
@ -4115,10 +4115,10 @@ static int copy_remapped_data(struct btrfs_fs_info *fs_info, u64 old_addr,
|
|||
u64 new_addr, u64 length)
|
||||
{
|
||||
int ret;
|
||||
u64 copy_len = min_t(u64, length, SZ_1M);
|
||||
const u64 copy_len = min_t(u64, length, SZ_1M);
|
||||
struct page **pages;
|
||||
struct reloc_io_private priv;
|
||||
unsigned int nr_pages = DIV_ROUND_UP(length, PAGE_SIZE);
|
||||
const unsigned int nr_pages = DIV_ROUND_UP(copy_len, PAGE_SIZE);
|
||||
|
||||
pages = kzalloc_objs(struct page *, nr_pages, GFP_NOFS);
|
||||
if (!pages)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user