Skip to contentSkip to conversation

bcachefs: fix error path of __bch2_read_super()

PATCH Superseded Chao Yu 2 participants 3 messages Apr 11, 2024 – Apr 12, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 bcachefs: fix error path of __bch2_read_super()

In __bch2_read_super(), if kstrdup() fails, it needs to release memory in sb->holder, fix to call bch2_free_super() in the error path.

---
 fs/bcachefs/super-io.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/bcachefs/super-io.c +4 -2
index ad28e370b640..cec1470c2dd9 100644
@@ -698,8 +698,10 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
 		return -ENOMEM;
 
 	sb->sb_name = kstrdup(path, GFP_KERNEL);
-	if (!sb->sb_name)
-		return -ENOMEM;
+	if (!sb->sb_name) {
+		ret = -ENOMEM;
+		goto err;
+	}
 
 #ifndef __KERNEL__
 	if (opt_get(*opts, direct_io) == false)
Signature · 1 line
2.40.1
#1 lore raw
Quoted 13 lines · Chao Yu

In __bch2_read_super(), if kstrdup() fails, it needs to release memory in sb->holder, fix to call bch2_free_super() in the error path.

---
  fs/bcachefs/super-io.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
fs/bcachefs/super-io.c +0 -0
index ad28e370b640..cec1470c2dd9 100644

fs/bcachefs/super-io.c static int __bch2_read_super(const char *path, struct bch_opts *opts, · line 702

Quoted 7 lines
fs/bcachefs/super-io.c +2 -2
@@ -698,8 +698,10 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
  		return -ENOMEM;
 
  	sb->sb_name = kstrdup(path, GFP_KERNEL);
-	if (!sb->sb_name)
-		return -ENOMEM;
+	if (!sb->sb_name) {
+		ret = -ENOMEM;

maybe you should fill err with message info by prt_printf(xxx), because err with no message info when printed in bch2_print_opts.

Quoted 5 lines
fs/bcachefs/super-io.c +2 -0
+		goto err;
+	}
 
  #ifndef __KERNEL__
  	if (opt_get(*opts, direct_io) == false)
author
#2 lore raw
Quoted 11 lines · Hongbo Li
Quoted 8 lines · Chao Yu

In __bch2_read_super(), if kstrdup() fails, it needs to release memory in sb->holder, fix to call bch2_free_super() in the error path.

---
  fs/bcachefs/super-io.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 12 lines

fs/bcachefs/super-io.c static int __bch2_read_super(const char *path, struct bch_opts *opts, · line 701

Quoted 11 lines
fs/bcachefs/super-io.c +2 -2
index ad28e370b640..cec1470c2dd9 100644
@@ -698,8 +698,10 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
           return -ENOMEM;
       sb->sb_name = kstrdup(path, GFP_KERNEL);
-    if (!sb->sb_name)
-        return -ENOMEM;
+    if (!sb->sb_name) {
+        ret = -ENOMEM;

maybe you should fill err with message info by prt_printf(xxx), because err with no message info when printed in bch2_print_opts.

Oh, yes, will revise in v2, thank you for the comments.

Thanks,

Quoted 4 lines
Quoted 4 lines
fs/bcachefs/super-io.c +2 -0
+        goto err;
+    }
   #ifndef __KERNEL__
       if (opt_get(*opts, direct_io) == false)