diff mbox series

[1/2] btrfs: Move dereference behind null check in check integrity

Message ID 20191207221818.3641-2-sebastian.scherbel@fau.de (mailing list archive)
State New, archived
Headers show
Series btrfs: Move dereference behind null checks | expand

Commit Message

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

Regarding Bug 205003, point 1
The struct "state" is currently dereferenced before being checked
for null later on. This patch moves the dereference after the null check
to avoid a possible null pointer dereference.

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/check-integrity.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 0b52ab4cb964..fc429436765c 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -629,7 +629,7 @@  static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup(dev_t dev,
 static int btrfsic_process_superblock(struct btrfsic_state *state,
 				      struct btrfs_fs_devices *fs_devices)
 {
-	struct btrfs_fs_info *fs_info = state->fs_info;
+	struct btrfs_fs_info *fs_info;
 	struct btrfs_super_block *selected_super;
 	struct list_head *dev_head = &fs_devices->devices;
 	struct btrfs_device *device;
@@ -638,6 +638,8 @@  static int btrfsic_process_superblock(struct btrfsic_state *state,
 	int pass;
 
 	BUG_ON(NULL == state);
+	fs_info = state->fs_info;
+
 	selected_super = kzalloc(sizeof(*selected_super), GFP_NOFS);
 	if (NULL == selected_super) {
 		pr_info("btrfsic: error, kmalloc failed!\n");