]> git.hungrycats.org Git - linux/commit
btrfs: free unlinked replace target on initialization failure
authorGuanghui Yang <3497809730@qq.com>
Sat, 8 Aug 2026 06:13:55 +0000 (14:13 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Sep 2026 11:23:36 +0000 (13:23 +0200)
commit127874796a411e121474018e4f4d3555808bac33
treedc63fbd833a21f9227f8e9e07798ee216f269b93
parentfd73f4a6659897191fa0d40695fe370925dd3780
btrfs: free unlinked replace target on initialization failure

btrfs_init_dev_replace_tgtdev() allocates the replacement target before
looking up its dev_t and initializing its zoned device information. If
either lookup_bdev() or btrfs_get_dev_zone_info() fails, the device has
not been linked into fs_devices->devices yet, but the error path only
drops the block device file reference.

Free the allocated device on this error path to release its name,
allocation state, zone info, and the device itself.

The issue was found by a failure-path metadata residual analyzer and
verified with targeted failure injection on v6.14.

Assisted-by: Codex:gpt-5
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Guanghui Yang <3497809730@qq.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h