linux-bcachefs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcachefs: fix error path of __bch2_read_super()
@ 2024-04-11 10:08 Chao Yu
  2024-04-11 11:29 ` Hongbo Li
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2024-04-11 10:08 UTC (permalink / raw)
  To: kent.overstreet, bfoster; +Cc: linux-bcachefs, 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.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/bcachefs/super-io.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
index ad28e370b640..cec1470c2dd9 100644
--- a/fs/bcachefs/super-io.c
+++ b/fs/bcachefs/super-io.c
@@ -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)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bcachefs: fix error path of __bch2_read_super()
  2024-04-11 10:08 [PATCH] bcachefs: fix error path of __bch2_read_super() Chao Yu
@ 2024-04-11 11:29 ` Hongbo Li
  2024-04-12  6:32   ` Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Hongbo Li @ 2024-04-11 11:29 UTC (permalink / raw)
  To: Chao Yu, kent.overstreet, bfoster; +Cc: linux-bcachefs



On 2024/4/11 18:08, Chao Yu wrote:
> 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.
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
>   fs/bcachefs/super-io.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
> index ad28e370b640..cec1470c2dd9 100644
> --- a/fs/bcachefs/super-io.c
> +++ b/fs/bcachefs/super-io.c
> @@ -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.
> +		goto err;
> +	}
>   
>   #ifndef __KERNEL__
>   	if (opt_get(*opts, direct_io) == false)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bcachefs: fix error path of __bch2_read_super()
  2024-04-11 11:29 ` Hongbo Li
@ 2024-04-12  6:32   ` Chao Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2024-04-12  6:32 UTC (permalink / raw)
  To: Hongbo Li, kent.overstreet, bfoster; +Cc: linux-bcachefs

On 2024/4/11 19:29, Hongbo Li wrote:
> 
> 
> On 2024/4/11 18:08, Chao Yu wrote:
>> 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.
>>
>> Signed-off-by: Chao Yu <chao@kernel.org>
>> ---
>>   fs/bcachefs/super-io.c | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
>> index ad28e370b640..cec1470c2dd9 100644
>> --- a/fs/bcachefs/super-io.c
>> +++ b/fs/bcachefs/super-io.c
>> @@ -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,

>> +        goto err;
>> +    }
>>   #ifndef __KERNEL__
>>       if (opt_get(*opts, direct_io) == false)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-12  6:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 10:08 [PATCH] bcachefs: fix error path of __bch2_read_super() Chao Yu
2024-04-11 11:29 ` Hongbo Li
2024-04-12  6:32   ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).