[2/2] btrfs: Move dereference behind null check in check volumes
diff mbox series

Message ID 20191207221818.3641-3-sebastian.scherbel@fau.de
State New
Headers show
Series
  • btrfs: Move dereference behind null checks
Related show

Commit Message

Sebastian Dec. 7, 2019, 10:18 p.m. UTC
From: Sebastian Scherbel <sebastian.scherbel@fau.de>

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@fau.de>
Co-developed-by: Ole Wiedemann <ole.wiedemann@fau.de>
Signed-off-by: Ole Wiedemann <ole.wiedemann@fau.de>
---
 fs/btrfs/volumes.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch
diff mbox series

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);