Skip to contentSkip to conversation

erofs: [PATCH v2] Prevent entering an infinite loop when i is 0

PATCH Superseded liujinbao1 2 participants 3 messages Aug 23, 2024 – Aug 29, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

liujinbao1

author
#0 lore raw

PATCH 1/1 erofs: [PATCH v2] Prevent entering an infinite loop when i is 0

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

---
 fs/erofs/decompressor.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 42 lines

Hi,

Quoted 5 lines · On 2024/8/22 14:27, liujinbao1 wrote:

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

Missing your Signed-off-by here.

Quoted 9 lines
---
 fs/erofs/decompressor.c | 2 ++
 1 file changed, 2 insertions(+)
fs/erofs/decompressor.c index renamed from fs/erofs/decompressor.c +0 -0

c2253b6a5416..1b2b8cc7911c 100644

fs/erofs/decompressor.c int __init z_erofs_init_decompressor(void) · line 546

Quoted 8 lines
fs/erofs/decompressor.c +2 -0
@@ -539,6 +539,8 @@ int __init z_erofs_init_decompressor(void)
     for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
             err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
             if (err) {
+                    if (!i)
+                            return err;
                     while (--i)
                             if (z_erofs_decomp[i])
                                     z_erofs_decomp[i]->exit();

Thanks for catching this, how about the following diff (space-demaged).

If it looks good to you, could you please send another version?

fs/erofs/decompressor.c +0 -1
@@ -534,18 +534,16 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 
 int __init z_erofs_init_decompressor(void)
 {
-      int i, err;

fs/erofs/decompressor.c int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) · line 545

Quoted 10 lines
fs/erofs/decompressor.c +2 -2
+      int i, err = 0;
 
       for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
               err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
-              if (err) {
+              if (err && i)
                       while (--i)
                               if (z_erofs_decomp[i])
                                       z_erofs_decomp[i]->exit();
-                      return err;

+ break;

fs/erofs/decompressor.c int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) · line 548

Quoted 6 lines
fs/erofs/decompressor.c +1 -2
-              }
       }
-      return 0;
+      return err;
 }
 

missing break?

Signature · 1 line
2.25.1
#1 lore raw
Quoted 12 lines · On 2024/8/23 11:05, liujinbao1 wrote:

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

---
  fs/erofs/decompressor.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 1 line

Hi,

The patch is corrupted and the patch subject
line is also broken.

I think it should be:
[PATCH v2] erofs: prevent entering an infinite loop when i is 0

Quoted 58 lines
Quoted 51 lines · On 2024/8/22 14:27, liujinbao1 wrote:
Quoted 5 lines

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

Missing your Signed-off-by here.

Quoted 9 lines
---
  fs/erofs/decompressor.c | 2 ++
  1 file changed, 2 insertions(+)
fs/erofs/decompressor.c index renamed from fs/erofs/decompressor.c +0 -0

c2253b6a5416..1b2b8cc7911c 100644

fs/erofs/decompressor.c int __init z_erofs_init_decompressor(void) · line 546

Quoted 8 lines
fs/erofs/decompressor.c +2 -0
@@ -539,6 +539,8 @@ int __init z_erofs_init_decompressor(void)
      for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
              err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
              if (err) {
+                    if (!i)
+                            return err;
                      while (--i)
                              if (z_erofs_decomp[i])
                                      z_erofs_decomp[i]->exit();

Thanks for catching this, how about the following diff (space-demaged).

If it looks good to you, could you please send another version?

fs/erofs/decompressor.c +2 -3
@@ -534,18 +534,16 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 
 int __init z_erofs_init_decompressor(void)
 {
-      int i, err;
+      int i, err = 0;
 
        for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
                err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
-              if (err) {
+              if (err && i)
                        while (--i)
                                if (z_erofs_decomp[i])
                                        z_erofs_decomp[i]->exit();
-                      return err;
(quoted diff) +1 -0
+						break;

fs/erofs/decompressor.c int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) · line 548

Quoted 6 lines
fs/erofs/decompressor.c +1 -2
-              }
        }
-      return 0;
+      return err;
 }
 
Quoted 1 line

missing break?

Why needing a break?

Thanks,
Gao Xiang

#2 lore raw

Hi liujinbao1,

Since it's a trivial bug which can be simply fixed, I just would like to confirm if you still have time and interest to send a workable patch (after a week).

If you don't have time to follow up, I will ask Hongzhen to fix this with your "Reported-by:" tomorrow.

Thanks,
Gao Xiang

Quoted 86 lines · Gao Xiang
Quoted 12 lines · On 2024/8/23 11:05, liujinbao1 wrote:

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

---
  fs/erofs/decompressor.c | 8 +++-----

  1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 1 line

Hi,

The patch is corrupted and the patch subject
line is also broken.

I think it should be:
[PATCH v2] erofs: prevent entering an infinite loop when i is 0

Quoted 52 lines
Quoted 41 lines · On 2024/8/22 14:27, liujinbao1 wrote:
Quoted 5 lines

From: liujinbao1 <[email protected]>

When i=0 and err is not equal to 0,
the while(-1) loop will enter into an
infinite loop. This patch avoids this issue.

Missing your Signed-off-by here.

Quoted 9 lines

---
  fs/erofs/decompressor.c | 2 ++

  1 file changed, 2 insertions(+)
fs/erofs/decompressor.c index renamed from fs/erofs/decompressor.c +0 -0

c2253b6a5416..1b2b8cc7911c 100644

fs/erofs/decompressor.c int __init z_erofs_init_decompressor(void) · line 546

Quoted 8 lines
fs/erofs/decompressor.c +2 -0
@@ -539,6 +539,8 @@ int __init z_erofs_init_decompressor(void)
       for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
               err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
               if (err) {
+                    if (!i)
+                            return err;
                       while (--i)
                               if (z_erofs_decomp[i])
                                       z_erofs_decomp[i]->exit();

Thanks for catching this, how about the following diff (space-demaged).

If it looks good to you, could you please send another version?

fs/erofs/decompressor.c +0 -1
@@ -534,18 +534,16 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 
 int __init z_erofs_init_decompressor(void)
 {
-      int i, err;

fs/erofs/decompressor.c int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) · line 545

Quoted 10 lines
fs/erofs/decompressor.c +2 -2
+      int i, err = 0;
 
         for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
                 err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
-              if (err) {
+              if (err && i)
                         while (--i)
                                 if (z_erofs_decomp[i])
                                         z_erofs_decomp[i]->exit();
-                      return err;

+                        break;

Quoted 7 lines

fs/erofs/decompressor.c int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) · line 548

Quoted 6 lines
fs/erofs/decompressor.c +1 -2
-              }
         }
-      return 0;
+      return err;
 }
 

missing break?

Why needing a break?

Thanks,
Gao Xiang