btrfs: defrag: use auto kfree in defrag_one_range() for folios array

Use AUTO_KFREE() for the folios array, avoiding two kfree() calls, one of
them in a very specific error path.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Filipe Manana 2026-06-24 18:09:22 +01:00 committed by David Sterba
parent 28bc34d647
commit d5b675c30a

View File

@ -1169,7 +1169,7 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
struct defrag_target_range *entry;
struct defrag_target_range *tmp;
LIST_HEAD(target_list);
struct folio **folios;
struct folio AUTO_KFREE(*folios);
const u32 sectorsize = inode->root->fs_info->sectorsize;
u64 cur = start;
const unsigned int nr_pages = ((start + len - 1) >> PAGE_SHIFT) -
@ -1196,10 +1196,8 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
* range or the extent lock.
*/
ret = btrfs_delalloc_reserve_space(inode, &data_reserved, start, len);
if (ret < 0) {
kfree(folios);
if (ret < 0)
return ret;
}
/* Prepare all pages */
for (int i = 0; cur < start + len && i < nr_pages; i++) {
@ -1251,7 +1249,6 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
folio_unlock(folios[i]);
folio_put(folios[i]);
}
kfree(folios);
btrfs_delalloc_release_extents(inode, len);
if (last_defrag_end < start + len)
btrfs_delalloc_release_space(inode, data_reserved, last_defrag_end,