Skip to contentSkip to conversation

btrfs: Fix an error pointer vs NULL check

PATCH In review Dan Carpenter 3 participants 3 messages Aug 5, 2020 – Aug 10, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Fix an error pointer vs NULL check

The btrfs_get_subvol_name_from_objectid() function never returns NULL, it returns error pointers. Update the check accordinglingly to prevent an Oops.

Fixes ca346708eb17 ("btrfs: don't show full path of bind mounts in subvol=")
---
 fs/btrfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 53639de3a064..e529ddb35b87 100644
@@ -1475,7 +1475,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 		  BTRFS_I(d_inode(dentry))->root->root_key.objectid);
 	subvol_name = btrfs_get_subvol_name_from_objectid(info,
 			BTRFS_I(d_inode(dentry))->root->root_key.objectid);
-	if (subvol_name) {
+	if (!IS_ERR(subvol_name)) {
 		seq_puts(seq, ",subvol=");
 		seq_escape(seq, subvol_name, " \t\n\\");
 		kfree(subvol_name);
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

The btrfs_get_subvol_name_from_objectid() function never returns NULL, it returns error pointers. Update the check accordinglingly to prevent an Oops.

Fixes ca346708eb17 ("btrfs: don't show full path of bind mounts in subvol=")
Quoted 18 lines
---
 fs/btrfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 53639de3a064..e529ddb35b87 100644
@@ -1475,7 +1475,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 		  BTRFS_I(d_inode(dentry))->root->root_key.objectid);
 	subvol_name = btrfs_get_subvol_name_from_objectid(info,
 			BTRFS_I(d_inode(dentry))->root->root_key.objectid);
-	if (subvol_name) {
+	if (!IS_ERR(subvol_name)) {
 		seq_puts(seq, ",subvol=");
 		seq_escape(seq, subvol_name, " \t\n\\");
 		kfree(subvol_name);
#2 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

The btrfs_get_subvol_name_from_objectid() function never returns NULL, it returns error pointers. Update the check accordinglingly to prevent an Oops.

Fixes ca346708eb17 ("btrfs: don't show full path of bind mounts in subvol=")

Thanks for catching it, the patch is in a development branch and the commit id is unstable so I'll fold the fixup.