linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails
@ 2023-11-01 10:49 Christophe JAILLET
  2023-11-01 10:49 ` [PATCH 2/2] vboxsf: Remove usage of the deprecated ida_simple_xx() API Christophe JAILLET
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Christophe JAILLET @ 2023-11-01 10:49 UTC (permalink / raw)
  To: Hans de Goede, Christoph Hellwig, Al Viro
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-fsdevel

If an load_nls_xxx() function fails a few lines above, the 'sbi->bdi_id' is
still 0.
So, in the error handling path, we will call ida_simple_remove(..., 0)
which is not allocated yet.

In order to prevent a spurious "ida_free called for id=0 which is not
allocated." message, tweak the error handling path and add a new label.

Fixes: 0fd169576648 ("fs: Add VirtualBox guest shared folder (vboxsf) support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 fs/vboxsf/super.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
index 1fb8f4df60cb..9848af78215b 100644
--- a/fs/vboxsf/super.c
+++ b/fs/vboxsf/super.c
@@ -151,7 +151,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
 		if (!sbi->nls) {
 			vbg_err("vboxsf: Count not load '%s' nls\n", nls_name);
 			err = -EINVAL;
-			goto fail_free;
+			goto fail_destroy_idr;
 		}
 	}
 
@@ -224,6 +224,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
 		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
 	if (sbi->nls)
 		unload_nls(sbi->nls);
+fail_destroy_idr:
 	idr_destroy(&sbi->ino_idr);
 	kfree(sbi);
 	return err;
-- 
2.34.1


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

* [PATCH 2/2] vboxsf: Remove usage of the deprecated ida_simple_xx() API
  2023-11-01 10:49 [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Christophe JAILLET
@ 2023-11-01 10:49 ` Christophe JAILLET
  2023-11-01 10:59 ` [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Hans de Goede
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Christophe JAILLET @ 2023-11-01 10:49 UTC (permalink / raw)
  To: Hans de Goede
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-fsdevel

ida_alloc() and ida_free() should be preferred to the deprecated
ida_simple_get() and ida_simple_remove().

This is less verbose.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 fs/vboxsf/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
index 9848af78215b..0f67f2d8b651 100644
--- a/fs/vboxsf/super.c
+++ b/fs/vboxsf/super.c
@@ -155,7 +155,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
 		}
 	}
 
-	sbi->bdi_id = ida_simple_get(&vboxsf_bdi_ida, 0, 0, GFP_KERNEL);
+	sbi->bdi_id = ida_alloc(&vboxsf_bdi_ida, GFP_KERNEL);
 	if (sbi->bdi_id < 0) {
 		err = sbi->bdi_id;
 		goto fail_free;
@@ -221,7 +221,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
 	vboxsf_unmap_folder(sbi->root);
 fail_free:
 	if (sbi->bdi_id >= 0)
-		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
+		ida_free(&vboxsf_bdi_ida, sbi->bdi_id);
 	if (sbi->nls)
 		unload_nls(sbi->nls);
 fail_destroy_idr:
@@ -269,7 +269,7 @@ static void vboxsf_put_super(struct super_block *sb)
 
 	vboxsf_unmap_folder(sbi->root);
 	if (sbi->bdi_id >= 0)
-		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
+		ida_free(&vboxsf_bdi_ida, sbi->bdi_id);
 	if (sbi->nls)
 		unload_nls(sbi->nls);
 
-- 
2.34.1


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

* Re: [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails
  2023-11-01 10:49 [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Christophe JAILLET
  2023-11-01 10:49 ` [PATCH 2/2] vboxsf: Remove usage of the deprecated ida_simple_xx() API Christophe JAILLET
@ 2023-11-01 10:59 ` Hans de Goede
  2023-11-02 12:30 ` Matthew Wilcox
  2024-04-03 14:10 ` Hans de Goede
  3 siblings, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2023-11-01 10:59 UTC (permalink / raw)
  To: Christophe JAILLET, Christoph Hellwig, Al Viro
  Cc: linux-kernel, kernel-janitors, linux-fsdevel

Hi Christophe,

On 11/1/23 11:49, Christophe JAILLET wrote:
> If an load_nls_xxx() function fails a few lines above, the 'sbi->bdi_id' is
> still 0.
> So, in the error handling path, we will call ida_simple_remove(..., 0)
> which is not allocated yet.
> 
> In order to prevent a spurious "ida_free called for id=0 which is not
> allocated." message, tweak the error handling path and add a new label.
> 
> Fixes: 0fd169576648 ("fs: Add VirtualBox guest shared folder (vboxsf) support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Thank you, both patches look good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

for the series.

Regards,

Hans



> ---
>  fs/vboxsf/super.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
> index 1fb8f4df60cb..9848af78215b 100644
> --- a/fs/vboxsf/super.c
> +++ b/fs/vboxsf/super.c
> @@ -151,7 +151,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>  		if (!sbi->nls) {
>  			vbg_err("vboxsf: Count not load '%s' nls\n", nls_name);
>  			err = -EINVAL;
> -			goto fail_free;
> +			goto fail_destroy_idr;
>  		}
>  	}
>  
> @@ -224,6 +224,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>  		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
>  	if (sbi->nls)
>  		unload_nls(sbi->nls);
> +fail_destroy_idr:
>  	idr_destroy(&sbi->ino_idr);
>  	kfree(sbi);
>  	return err;


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

* Re: [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails
  2023-11-01 10:49 [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Christophe JAILLET
  2023-11-01 10:49 ` [PATCH 2/2] vboxsf: Remove usage of the deprecated ida_simple_xx() API Christophe JAILLET
  2023-11-01 10:59 ` [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Hans de Goede
@ 2023-11-02 12:30 ` Matthew Wilcox
  2023-11-02 21:21   ` Christophe JAILLET
  2024-04-03 14:10 ` Hans de Goede
  3 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2023-11-02 12:30 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Hans de Goede, Christoph Hellwig, Al Viro, linux-kernel,
	kernel-janitors, linux-fsdevel

On Wed, Nov 01, 2023 at 11:49:48AM +0100, Christophe JAILLET wrote:
> If an load_nls_xxx() function fails a few lines above, the 'sbi->bdi_id' is
> still 0.
> So, in the error handling path, we will call ida_simple_remove(..., 0)
> which is not allocated yet.
> 
> In order to prevent a spurious "ida_free called for id=0 which is not
> allocated." message, tweak the error handling path and add a new label.

That's not spurious!  You're freeing something that wasn't allocated.
A good quality malloc allocation will warn you if you free() a random
pointer.  I agree with everything abuot this patch (and the next) except
for the changelog.

> Fixes: 0fd169576648 ("fs: Add VirtualBox guest shared folder (vboxsf) support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  fs/vboxsf/super.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
> index 1fb8f4df60cb..9848af78215b 100644
> --- a/fs/vboxsf/super.c
> +++ b/fs/vboxsf/super.c
> @@ -151,7 +151,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>  		if (!sbi->nls) {
>  			vbg_err("vboxsf: Count not load '%s' nls\n", nls_name);
>  			err = -EINVAL;
> -			goto fail_free;
> +			goto fail_destroy_idr;
>  		}
>  	}
>  
> @@ -224,6 +224,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>  		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
>  	if (sbi->nls)
>  		unload_nls(sbi->nls);
> +fail_destroy_idr:
>  	idr_destroy(&sbi->ino_idr);
>  	kfree(sbi);
>  	return err;
> -- 
> 2.34.1
> 
> 

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

* Re: [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails
  2023-11-02 12:30 ` Matthew Wilcox
@ 2023-11-02 21:21   ` Christophe JAILLET
  0 siblings, 0 replies; 6+ messages in thread
From: Christophe JAILLET @ 2023-11-02 21:21 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Hans de Goede, Christoph Hellwig, Al Viro, linux-kernel,
	kernel-janitors, linux-fsdevel

Le 02/11/2023 à 13:30, Matthew Wilcox a écrit :
> On Wed, Nov 01, 2023 at 11:49:48AM +0100, Christophe JAILLET wrote:
>> If an load_nls_xxx() function fails a few lines above, the 'sbi->bdi_id' is
>> still 0.
>> So, in the error handling path, we will call ida_simple_remove(..., 0)
>> which is not allocated yet.
>>
>> In order to prevent a spurious "ida_free called for id=0 which is not
>> allocated." message, tweak the error handling path and add a new label.
> 
> That's not spurious!

My fault, as a non-native English speaking man.
I've always sought that spurious was meaning "odd" or "strange", but I 
was wrong :(

Here, a better wording could be "to prevent an un-expected "ida..."".
Is that ok for you?

Or the last sentence could shortened to only "In order to fix it, tweak 
the error handling path and add a new label.".

CJ

> You're freeing something that wasn't allocated.
> A good quality malloc allocation will warn you if you free() a random
> pointer.  I agree with everything abuot this patch (and the next) except
> for the changelog.
> 
>> Fixes: 0fd169576648 ("fs: Add VirtualBox guest shared folder (vboxsf) support")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   fs/vboxsf/super.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
>> index 1fb8f4df60cb..9848af78215b 100644
>> --- a/fs/vboxsf/super.c
>> +++ b/fs/vboxsf/super.c
>> @@ -151,7 +151,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>>   		if (!sbi->nls) {
>>   			vbg_err("vboxsf: Count not load '%s' nls\n", nls_name);
>>   			err = -EINVAL;
>> -			goto fail_free;
>> +			goto fail_destroy_idr;
>>   		}
>>   	}
>>   
>> @@ -224,6 +224,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>>   		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
>>   	if (sbi->nls)
>>   		unload_nls(sbi->nls);
>> +fail_destroy_idr:
>>   	idr_destroy(&sbi->ino_idr);
>>   	kfree(sbi);
>>   	return err;
>> -- 
>> 2.34.1
>>
>>
> 
> 


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

* Re: [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails
  2023-11-01 10:49 [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Christophe JAILLET
                   ` (2 preceding siblings ...)
  2023-11-02 12:30 ` Matthew Wilcox
@ 2024-04-03 14:10 ` Hans de Goede
  3 siblings, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2024-04-03 14:10 UTC (permalink / raw)
  To: Christophe JAILLET, Christoph Hellwig, Al Viro
  Cc: linux-kernel, kernel-janitors, linux-fsdevel

Hi,

On 11/1/23 11:49 AM, Christophe JAILLET wrote:
> If an load_nls_xxx() function fails a few lines above, the 'sbi->bdi_id' is
> still 0.
> So, in the error handling path, we will call ida_simple_remove(..., 0)
> which is not allocated yet.
> 
> In order to prevent a spurious "ida_free called for id=0 which is not
> allocated." message, tweak the error handling path and add a new label.
> 
> Fixes: 0fd169576648 ("fs: Add VirtualBox guest shared folder (vboxsf) support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Thanks, both patches in this series look good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

I have added both patches to my local vboxsf branch now and I'll send
out a pull-request with this and a couple of other vboxsf fixes
soon.

Regards,

Hans





> ---
>  fs/vboxsf/super.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
> index 1fb8f4df60cb..9848af78215b 100644
> --- a/fs/vboxsf/super.c
> +++ b/fs/vboxsf/super.c
> @@ -151,7 +151,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>  		if (!sbi->nls) {
>  			vbg_err("vboxsf: Count not load '%s' nls\n", nls_name);
>  			err = -EINVAL;
> -			goto fail_free;
> +			goto fail_destroy_idr;
>  		}
>  	}
>  
> @@ -224,6 +224,7 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
>  		ida_simple_remove(&vboxsf_bdi_ida, sbi->bdi_id);
>  	if (sbi->nls)
>  		unload_nls(sbi->nls);
> +fail_destroy_idr:
>  	idr_destroy(&sbi->ino_idr);
>  	kfree(sbi);
>  	return err;


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

end of thread, other threads:[~2024-04-03 14:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-01 10:49 [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Christophe JAILLET
2023-11-01 10:49 ` [PATCH 2/2] vboxsf: Remove usage of the deprecated ida_simple_xx() API Christophe JAILLET
2023-11-01 10:59 ` [PATCH 1/2] vboxsf: Avoid an spurious warning if load_nls_xxx() fails Hans de Goede
2023-11-02 12:30 ` Matthew Wilcox
2023-11-02 21:21   ` Christophe JAILLET
2024-04-03 14:10 ` Hans de Goede

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).