From: Joe Perches <joe@perches.com>
To: Gao Xiang <hsiangkao@redhat.com>, Colin King <colin.king@canonical.com>
Cc: kernel-janitors@vger.kernel.org, Gao Xiang <xiang@kernel.org>,
linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] erofs: fix uninitialized variable i used in a while-loop
Date: Tue, 06 Apr 2021 20:38:44 -0700 [thread overview]
Message-ID: <b56a44542a338583279893870ec819d4b1b4e23b.camel@perches.com> (raw)
In-Reply-To: <20210406235401.GA210667@xiangao.remote.csb>
On Wed, 2021-04-07 at 07:54 +0800, Gao Xiang wrote:
> Hi Colin,
>
> On Tue, Apr 06, 2021 at 05:27:18PM +0100, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > The while-loop iterates until src is non-null or i is 3, however, the
> > loop counter i is not intinitialied to zero, causing incorrect iteration
> > counts. Fix this by initializing it to zero.
> >
> > Addresses-Coverity: ("Uninitialized scalar variable")
> > Fixes: 1aa5f2e2feed ("erofs: support decompress big pcluster for lz4 backend")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
>
> Thank you very much for catching this! It looks good to me,
> Reviewed-by: Gao Xiang <hsiangkao@redhat.com>
>
> (btw, may I fold this into the original patchset? since such big pcluster
> patchset is just applied to for-next for further integration testing, and
> the commit id is not stable yet..)
>
> Thanks,
> Gao Xiang
I think this code is odd and would be more intelligible using
a for loop like:
---
fs/erofs/decompressor.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 27aa6a99b371..5a64f4649414 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -286,28 +286,24 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq,
}
ret = alg->prepare_destpages(rq, pagepool);
- if (ret < 0) {
+ if (ret < 0)
return ret;
- } else if (ret) {
+ if (ret) {
dst = page_address(*rq->out);
dst_maptype = 1;
goto dstmap_out;
}
- i = 0;
- while (1) {
+ for (i = 0; i < 3; i++) {
dst = vm_map_ram(rq->out, nrpages_out, -1);
-
+ if (dst) {
+ dst_maptype = 2;
+ goto dstmap_out;
+ }
/* retry two more times (totally 3 times) */
- if (dst || ++i >= 3)
- break;
vm_unmap_aliases();
}
-
- if (!dst)
- return -ENOMEM;
-
- dst_maptype = 2;
+ return -ENOMEM;
dstmap_out:
ret = alg->decompress(rq, dst + rq->pageofs_out);
next prev parent reply other threads:[~2021-04-07 3:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-06 16:27 [PATCH][next] erofs: fix uninitialized variable i used in a while-loop Colin King
2021-04-06 23:54 ` Gao Xiang
2021-04-07 3:38 ` Joe Perches [this message]
2021-04-07 3:51 ` 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=b56a44542a338583279893870ec819d4b1b4e23b.camel@perches.com \
--to=joe@perches.com \
--cc=colin.king@canonical.com \
--cc=hsiangkao@redhat.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).