Skip to contentSkip to conversation

f2fs: use kfree() to free super in read_raw_super_block()

PATCH In review Denis Efremov 4 participants 10 messages Jun 5, 2020 – Jun 18, 2020 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 f2fs: use kfree() to free super in read_raw_super_block()

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function.

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")
---
 fs/f2fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/super.c +1 -1
index 8a9955902d84..9a3c8eba37e2 100644
@@ -3130,7 +3130,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
 
 	/* No valid superblock */
 	if (!*raw_super)
-		kvfree(super);
+		kfree(super);
 	else
 		err = 0;
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/2 f2fs: use kfree() to free sbi in f2fs_fill_super()

Use kfree() instead of kvfree() to free sbi in f2fs_fill_super() because the memory is allocated with kzalloc() in the function.

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")
---
 fs/f2fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/super.c +1 -1
index 9a3c8eba37e2..39b644c7e9d4 100644
@@ -3812,7 +3812,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 free_sbi:
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi);
+	kfree(sbi);
 
 	/* give only one another chance */
 	if (retry_cnt > 0 && skip_recovery) {
Signature · 1 line
2.26.2
#2 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: use kfree() to free sbi in f2fs_fill_super()

Quoted 3 lines · Denis Efremov

Use kfree() instead of kvfree() to free sbi in f2fs_fill_super() because the memory is allocated with kzalloc() in the function.

Could you fix them in one patch?

In addition, we need to fix them in f2fs_put_super() as well.

Thanks,

Quoted 21 lines
Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")
---
 fs/f2fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/super.c +1 -1
index 9a3c8eba37e2..39b644c7e9d4 100644
@@ -3812,7 +3812,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 free_sbi:
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi);
+	kfree(sbi);
 
 	/* give only one another chance */
 	if (retry_cnt > 0 && skip_recovery) {
#4 lore raw

PATCH v2 1/1 f2fs: use kfree() instead of kvfree() to free superblock data

In reply to Denis Efremov

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function. Use kfree() instead of kvfree() to free sbi in f2fs_fill_super() and f2fs_put_super() because the memory is allocated with kzalloc().

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")

---
Changes in v2:
- Single patch instead of two separate patches
- kvfree fixed in f2fs_put_super

 fs/f2fs/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/super.c +3 -3
index 8a9955902d84..94bfc140bef9 100644
@@ -1257,7 +1257,7 @@ static void f2fs_put_super(struct super_block *sb)
 #ifdef CONFIG_UNICODE
 	utf8_unload(sbi->s_encoding);
 #endif
-	kvfree(sbi);
+	kfree(sbi);
 }
 
 int f2fs_sync_fs(struct super_block *sb, int sync)
@@ -3130,7 +3130,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
 
 	/* No valid superblock */
 	if (!*raw_super)
-		kvfree(super);
+		kfree(super);
 	else
 		err = 0;
 
@@ -3812,7 +3812,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 free_sbi:
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi);
+	kfree(sbi);
 
 	/* give only one another chance */
 	if (retry_cnt > 0 && skip_recovery) {
Signature · 1 line
2.26.2
#5 lore raw

Re: [PATCH v2] f2fs: use kfree() instead of kvfree() to free superblock data

Hello Denis,

Quoted 7 lines · Denis Efremov

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function. Use kfree() instead of kvfree() to free sbi in f2fs_fill_super() and f2fs_put_super() because the memory is allocated with kzalloc().

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")

I found two missing cases, so how about this?

fs/f2fs/super.c +5 -5
index f3c151169542..f913a63e93f0 100644
@@ -1206,7 +1206,7 @@ static void f2fs_put_super(struct super_block *sb)
 	sb->s_fs_info = NULL;
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi->raw_super);
+	kfree(sbi->raw_super);
 
 	destroy_device_list(sbi);
 	f2fs_destroy_xattr_caches(sbi);
@@ -1221,7 +1221,7 @@ static void f2fs_put_super(struct super_block *sb)
 #ifdef CONFIG_UNICODE
 	utf8_unload(sbi->s_encoding);
 #endif
-	kvfree(sbi);
+	kfree(sbi);
 }
 
 int f2fs_sync_fs(struct super_block *sb, int sync)
@@ -3101,7 +3101,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
 
 	/* No valid superblock */
 	if (!*raw_super)
-		kvfree(super);
+		kfree(super);
 	else
 		err = 0;
 
@@ -3779,11 +3779,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 #endif
 	kvfree(options);
 free_sb_buf:
-	kvfree(raw_super);
+	kfree(raw_super);
 free_sbi:
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi);
+	kfree(sbi);
 
 	/* give only one another chance */
 	if (retry_cnt > 0 && skip_recovery) {
#6 lore raw

PATCH v3 1/1 f2fs: use kfree() instead of kvfree() to free superblock data

In reply to Denis Efremov

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function. Use kfree() instead of kvfree() to free sbi, raw_super in f2fs_fill_super() and f2fs_put_super() because the memory is allocated with kzalloc().

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")

---
Changes in v2:
- Single patch instead of two separate patches
- kvfree fixed in f2fs_put_super
Changes in v3:
- raw_super added to the scope, thanks Chao Yu

 fs/f2fs/super.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/f2fs/super.c +5 -5
index 8a9955902d84..7b458268ea09 100644
@@ -1241,7 +1241,7 @@ static void f2fs_put_super(struct super_block *sb)
 	sb->s_fs_info = NULL;
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi->raw_super);
+	kfree(sbi->raw_super);
 
 	destroy_device_list(sbi);
 	f2fs_destroy_xattr_caches(sbi);
@@ -1257,7 +1257,7 @@ static void f2fs_put_super(struct super_block *sb)
 #ifdef CONFIG_UNICODE
 	utf8_unload(sbi->s_encoding);
 #endif
-	kvfree(sbi);
+	kfree(sbi);
 }
 
 int f2fs_sync_fs(struct super_block *sb, int sync)
@@ -3130,7 +3130,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
 
 	/* No valid superblock */
 	if (!*raw_super)
-		kvfree(super);
+		kfree(super);
 	else
 		err = 0;
 
@@ -3808,11 +3808,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	fscrypt_free_dummy_context(&F2FS_OPTION(sbi).dummy_enc_ctx);
 	kvfree(options);
 free_sb_buf:
-	kvfree(raw_super);
+	kfree(raw_super);
 free_sbi:
 	if (sbi->s_chksum_driver)
 		crypto_free_shash(sbi->s_chksum_driver);
-	kvfree(sbi);
+	kfree(sbi);
 
 	/* give only one another chance */
 	if (retry_cnt > 0 && skip_recovery) {
Signature · 1 line
2.26.2
#7 lore raw

Re: [PATCH v3] f2fs: use kfree() instead of kvfree() to free superblock data

Quoted 8 lines · Denis Efremov

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function. Use kfree() instead of kvfree() to free sbi, raw_super in f2fs_fill_super() and f2fs_put_super() because the memory is allocated with kzalloc().

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")

I don't think "Fixes" is appropriate here.

kvfree() still works on kmalloc'ed memory; it's just not preferred.

So this is more a cleanup than a fix.

- Eric

maintainer
#8 lore raw

Re: [PATCH v3] f2fs: use kfree() instead of kvfree() to free superblock data

Quoted 11 lines · Eric Biggers
Quoted 8 lines · Denis Efremov

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function. Use kfree() instead of kvfree() to free sbi, raw_super in f2fs_fill_super() and f2fs_put_super() because the memory is allocated with kzalloc().

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")

I don't think "Fixes" is appropriate here.

Agreed. I queued this Cl without it. :)
Thanks,

Quoted 6 lines

kvfree() still works on kmalloc'ed memory; it's just not preferred.

So this is more a cleanup than a fix.

- Eric

Reviewed-by
#9 lore raw

Re: [PATCH v3] f2fs: use kfree() instead of kvfree() to free superblock data

Quoted 10 lines · Jaegeuk Kim
Quoted 9 lines · Eric Biggers
Quoted 8 lines · Denis Efremov

Use kfree() instead of kvfree() to free super in read_raw_super_block() because the memory is allocated with kzalloc() in the function. Use kfree() instead of kvfree() to free sbi, raw_super in f2fs_fill_super() and f2fs_put_super() because the memory is allocated with kzalloc().

Fixes 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed")

Thanks,

Quoted 14 lines
Quoted 2 lines

I don't think "Fixes" is appropriate here.

Agreed. I queued this Cl without it. :)
Thanks,

Quoted 6 lines

kvfree() still works on kmalloc'ed memory; it's just not preferred.

So this is more a cleanup than a fix.

- Eric

.