From: Sebastian Scherbel <sebastian.scherbel@xxxxxx>
Regarding Bug 205003, point 2
The struct "tgtdev" is currently dereferenced before being checked
for null later on. This patch moves the derefernce after the null
check to avoid a possible null pointer dereference.
Furthermore WARN_ON is replaced by BUG_ON to prevent the subsequent
dereference of the null pointer.
Signed-off-by: Sebastian Scherbel <sebastian.scherbel@xxxxxx>
Co-developed-by: Ole Wiedemann <ole.wiedemann@xxxxxx>
Signed-off-by: Ole Wiedemann <ole.wiedemann@xxxxxx>
---
fs/btrfs/volumes.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d8e5560db285..12015f60f50d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2128,9 +2128,11 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev)
void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
{
- struct btrfs_fs_devices *fs_devices = tgtdev->fs_info->fs_devices;
+ struct btrfs_fs_devices *fs_devices;
+
+ BUG_ON(!tgtdev);
+ fs_devices = tgtdev->fs_info->fs_devices;
- WARN_ON(!tgtdev);
mutex_lock(&fs_devices->device_list_mutex);
btrfs_sysfs_rm_device_link(fs_devices, tgtdev);
--
2.20.1