Skip to contentSkip to conversation

Btrfs: make sure fs_info is not null before its field is used in __btrfs_panic

PATCH In review Wang Sheng-Hui 2 participants 3 messages Dec 7, 2012 – Dec 8, 2012 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: make sure fs_info is not null before its field is used in __btrfs_panic

We should make sure fs_info is not null before we refer to its field. Add simple check here.

---
 fs/btrfs/super.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 915ac14..c6a3633 100644
@@ -280,7 +280,7 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
 	vaf.va = &args;
 
 	errstr = btrfs_decode_error(fs_info, errno, nbuf);
-	if (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR)
+	if (fs_info && (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR))
 		panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
 			s_id, function, line, &vaf, errstr);
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 2 lines · Wang Sheng-Hui

We should make sure fs_info is not null before we refer to its field. Add simple check here.

Why? Is there any caller passing NULL @fs_info to this function?

Quoted 20 lines
---
 fs/btrfs/super.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 915ac14..c6a3633 100644
@@ -280,7 +280,7 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
 	vaf.va = &args;
 
 	errstr = btrfs_decode_error(fs_info, errno, nbuf);
-	if (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR)
+	if (fs_info && (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR))
 		panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
 			s_id, function, line, &vaf, errstr);
 
#2 lore raw
Quoted 4 lines · Li Zefan
Quoted 2 lines · Wang Sheng-Hui

We should make sure fs_info is not null before we refer to its field. Add simple check here.

Why? Is there any caller passing NULL @fs_info to this function?

At least for code clean now.

In __btrfs_panic, we have:
276 if (fs_info)
277 s_id = fs_info->sb->s_id;
So for the ->mount_opt field access, we'd better do the check first.

Quoted 19 lines
Quoted 19 lines
---
 fs/btrfs/super.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 915ac14..c6a3633 100644
@@ -280,7 +280,7 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
 	vaf.va = &args;
 
 	errstr = btrfs_decode_error(fs_info, errno, nbuf);
-	if (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR)
+	if (fs_info && (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR))
 		panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
 			s_id, function, line, &vaf, errstr);