public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs: [PATCH v2] Prevent entering an infinite loop when i is 0
@ 2024-08-23  3:05 liujinbao1
  2024-08-23 12:03 ` Gao Xiang
  0 siblings, 1 reply; 3+ messages in thread
From: liujinbao1 @ 2024-08-23  3:05 UTC (permalink / raw)
  To: xiang; +Cc: chao, linux-erofs, linux-kernel, mazhenhua, liujinbao1

From: liujinbao1 <liujinbao1@xiaomi.com>

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.

Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
---
 fs/erofs/decompressor.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

>Hi,
> 
>On 2024/8/22 14:27, liujinbao1 wrote:
>> From: liujinbao1 <liujinbao1@xiaomi.com>
>> 
>> 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.
> 
>> ---
>>  fs/erofs/decompressor.c | 2 ++
>>  1 file changed, 2 insertions(+)
>> 
>> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 
>> c2253b6a5416..1b2b8cc7911c 100644
>> --- a/fs/erofs/decompressor.c
>> +++ b/fs/erofs/decompressor.c
>> @@ -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?

>diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index c2253b6a5416..c9b2bc1309d2 100644
>--- a/fs/erofs/decompressor.c
>+++ b/fs/erofs/decompressor.c
>@@ -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;
+						break;
>-              }
>        }
>-      return 0;
>+      return err;
> }
>
missing break?
-- 
2.25.1


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

* Re: [PATCH] erofs: [PATCH v2] Prevent entering an infinite loop when i is 0
  2024-08-23  3:05 [PATCH] erofs: [PATCH v2] Prevent entering an infinite loop when i is 0 liujinbao1
@ 2024-08-23 12:03 ` Gao Xiang
  2024-08-29 11:15   ` Gao Xiang
  0 siblings, 1 reply; 3+ messages in thread
From: Gao Xiang @ 2024-08-23 12:03 UTC (permalink / raw)
  To: liujinbao1, xiang; +Cc: chao, linux-erofs, linux-kernel, mazhenhua, liujinbao1



On 2024/8/23 11:05, liujinbao1 wrote:
> From: liujinbao1 <liujinbao1@xiaomi.com>
> 
> 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.
> 
> Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
> ---
>   fs/erofs/decompressor.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
>> 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

>>
>> On 2024/8/22 14:27, liujinbao1 wrote:
>>> From: liujinbao1 <liujinbao1@xiaomi.com>
>>>
>>> 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.
>>
>>> ---
>>>   fs/erofs/decompressor.c | 2 ++
>>>   1 file changed, 2 insertions(+)
>>>
>>> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index
>>> c2253b6a5416..1b2b8cc7911c 100644
>>> --- a/fs/erofs/decompressor.c
>>> +++ b/fs/erofs/decompressor.c
>>> @@ -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?
> 
>> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index c2253b6a5416..c9b2bc1309d2 100644
>> --- a/fs/erofs/decompressor.c
>> +++ b/fs/erofs/decompressor.c
>> @@ -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;
> +						break;
>> -              }
>>         }
>> -      return 0;
>> +      return err;
>> }
>>
> missing break?

Why needing a break?

Thanks,
Gao Xiang


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

* Re: [PATCH] erofs: [PATCH v2] Prevent entering an infinite loop when i is 0
  2024-08-23 12:03 ` Gao Xiang
@ 2024-08-29 11:15   ` Gao Xiang
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2024-08-29 11:15 UTC (permalink / raw)
  To: liujinbao1
  Cc: chao, linux-erofs, linux-kernel, mazhenhua, liujinbao1, Gao Xiang,
	Hongzhen Luo

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

On 2024/8/23 20:03, Gao Xiang wrote:
> 
> 
> On 2024/8/23 11:05, liujinbao1 wrote:
>> From: liujinbao1 <liujinbao1@xiaomi.com>
>>
>> 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.
>>
>> Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
>> ---
>>   fs/erofs/decompressor.c | 8 +++-----
>>   1 file changed, 3 insertions(+), 5 deletions(-)
>>
>>> 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
> 
>>>
>>> On 2024/8/22 14:27, liujinbao1 wrote:
>>>> From: liujinbao1 <liujinbao1@xiaomi.com>
>>>>
>>>> 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.
>>>
>>>> ---
>>>>   fs/erofs/decompressor.c | 2 ++
>>>>   1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index
>>>> c2253b6a5416..1b2b8cc7911c 100644
>>>> --- a/fs/erofs/decompressor.c
>>>> +++ b/fs/erofs/decompressor.c
>>>> @@ -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?
>>
>>> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index c2253b6a5416..c9b2bc1309d2 100644
>>> --- a/fs/erofs/decompressor.c
>>> +++ b/fs/erofs/decompressor.c
>>> @@ -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;
>> +                        break;
>>> -              }
>>>         }
>>> -      return 0;
>>> +      return err;
>>> }
>>>
>> missing break?
> 
> Why needing a break?
> 
> Thanks,
> Gao Xiang


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

end of thread, other threads:[~2024-08-29 11:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-23  3:05 [PATCH] erofs: [PATCH v2] Prevent entering an infinite loop when i is 0 liujinbao1
2024-08-23 12:03 ` Gao Xiang
2024-08-29 11:15   ` Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox