From: liujinbao1 <jinbaoliu365@gmail.com>
To: xiang@kernel.org
Cc: chao@kernel.org, linux-erofs@lists.ozlabs.org,
linux-kernel@vger.kernel.org, mazhenhua@xiaomi.com,
liujinbao1 <liujinbao1@xiaomi.com>
Subject: [PATCH] erofs: [PATCH v2] Prevent entering an infinite loop when i is 0
Date: Fri, 23 Aug 2024 11:05:25 +0800 [thread overview]
Message-ID: <20240823030525.4081970-1-jinbaoliu365@gmail.com> (raw)
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
next reply other threads:[~2024-08-23 3:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 3:05 liujinbao1 [this message]
2024-08-23 12:03 ` Gao Xiang
2024-08-29 11:15 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240823030525.4081970-1-jinbaoliu365@gmail.com \
--to=jinbaoliu365@gmail.com \
--cc=chao@kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liujinbao1@xiaomi.com \
--cc=mazhenhua@xiaomi.com \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®