Skip to contentSkip to conversation

f2fs: use multiplication instead of division in sanity_check_raw_super

PATCH In review Liu Song via Linux-f2fs-devel 2 participants 3 messages Jul 1, 2019 – Jul 2, 2019 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: use multiplication instead of division in sanity_check_raw_super

From: Liu Song <[email protected]>

Use multiplication instead of division and be more consistent with f2fs_msg output information.

---
 fs/f2fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/super.c +1 -1
index af58b2cc21b8..eba4c0f9c347 100644
@@ -2489,7 +2489,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
 		return 1;
 	}
 
-	if ((segment_count / segs_per_sec) < total_sections) {
+	if (segment_count < (segs_per_sec * total_sections)) {
 		f2fs_msg(sb, KERN_INFO,
 			"Small segment_count (%u < %u * %u)",
 			segment_count, segs_per_sec, total_sections);
Signature · 8 lines
2.20.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#1 lore raw

Hi Song,

Quoted 15 lines · On 2019-7-1 21:38, Liu Song via Linux-f2fs-devel wrote:

From: Liu Song <[email protected]>

Use multiplication instead of division and be more consistent with f2fs_msg output information.

---
 fs/f2fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/super.c +0 -0
index af58b2cc21b8..eba4c0f9c347 100644

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2492

Quoted 4 lines
fs/f2fs/super.c +0 -1
@@ -2489,7 +2489,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
 		return 1;
 	}
 
-	if ((segment_count / segs_per_sec) < total_sections) {

I think we use division intentionally to avoid potential overflow when doing multiplication.

You can see the detailed commit message in below fixing patch:

0cfe75c5b011 ("f2fs: enhance sanity_check_raw_super() to avoid potential overflows")

Thanks,

Quoted 5 lines
fs/f2fs/super.c +1 -0
+	if (segment_count < (segs_per_sec * total_sections)) {
 		f2fs_msg(sb, KERN_INFO,
 			"Small segment_count (%u < %u * %u)",
 			segment_count, segs_per_sec, total_sections);
#2 lore raw

Hi Chao,

Thanks for your reply, I understand why there can't use multiplication, thanks a lot :D

Best regards
Liu Song

Quoted 26 lines

Hi Song,

Quoted 15 lines · On 2019-7-1 21:38, Liu Song via Linux-f2fs-devel wrote:

From: Liu Song <[email protected]>

Use multiplication instead of division and be more consistent with f2fs_msg output information.

---
 fs/f2fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/super.c +0 -0
index af58b2cc21b8..eba4c0f9c347 100644

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2492

Quoted 4 lines
fs/f2fs/super.c +0 -1
@@ -2489,7 +2489,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
   return 1;
  }
 
- if ((segment_count / segs_per_sec) < total_sections) {

I think we use division intentionally to avoid potential overflow when doing multiplication.

Quoted 11 lines

You can see the detailed commit message in below fixing patch:

0cfe75c5b011 ("f2fs: enhance sanity_check_raw_super() to avoid potential overflows")

Thanks,

Quoted 5 lines
fs/f2fs/super.c +1 -0
+ if (segment_count < (segs_per_sec * total_sections)) {
   f2fs_msg(sb, KERN_INFO,
    "Small segment_count (%u < %u * %u)",
    segment_count, segs_per_sec, total_sections);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel