[bug report] crypto: zstd - convert to acomp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Suman Kumar Chakraborty,

Commit f5ad93ffb541 ("crypto: zstd - convert to acomp") from Jun 16,
2025 (linux-next), leads to the following Smatch static checker
warning:

	crypto/zstd.c:273 zstd_decompress()
	warn: duplicate check 'scur' (previous on line 235)

crypto/zstd.c
    208 static int zstd_decompress(struct acomp_req *req)
    209 {
    210         struct crypto_acomp_stream *s;
    211         unsigned int total_out = 0;
    212         unsigned int scur, dcur;
    213         zstd_out_buffer outbuf;
    214         struct acomp_walk walk;
    215         zstd_in_buffer inbuf;
    216         struct zstd_ctx *ctx;
    217         size_t pending_bytes;
    218         int ret;
    219 
    220         s = crypto_acomp_lock_stream_bh(&zstd_streams);
    221         ctx = s->ctx;
    222 
    223         ret = acomp_walk_virt(&walk, req, true);
    224         if (ret)
    225                 goto out;
    226 
    227         ctx->dctx = zstd_init_dstream(ZSTD_MAX_SIZE, ctx->wksp, ctx->wksp_size);
    228         if (!ctx->dctx) {
    229                 ret = -EINVAL;
    230                 goto out;
    231         }
    232 
    233         do {
    234                 scur = acomp_walk_next_src(&walk);
    235                 if (scur) {
    236                         inbuf.pos = 0;
    237                         inbuf.size = scur;
    238                         inbuf.src = walk.src.virt.addr;
    239                 } else {
    240                         break;

If scur is NULL then we break.

    241                 }
    242 
    243                 do {
    244                         dcur = acomp_walk_next_dst(&walk);
    245                         if (dcur == req->dlen && scur == req->slen) {
    246                                 ret = zstd_decompress_one(req, ctx, walk.src.virt.addr,
    247                                                           walk.dst.virt.addr, &total_out);
    248                                 acomp_walk_done_dst(&walk, dcur);
    249                                 acomp_walk_done_src(&walk, scur);
    250                                 goto out;
    251                         }
    252 
    253                         if (!dcur) {
    254                                 ret = -ENOSPC;
    255                                 goto out;
    256                         }
    257 
    258                         outbuf.pos = 0;
    259                         outbuf.dst = (u8 *)walk.dst.virt.addr;
    260                         outbuf.size = dcur;
    261 
    262                         pending_bytes = zstd_decompress_stream(ctx->dctx, &outbuf, &inbuf);
    263                         if (ZSTD_isError(pending_bytes)) {
    264                                 ret = -EIO;
    265                                 goto out;
    266                         }
    267 
    268                         total_out += outbuf.pos;
    269 
    270                         acomp_walk_done_dst(&walk, outbuf.pos);
    271                 } while (scur != inbuf.pos);
    272 
--> 273                 if (scur)

No need to check.  It's weird that the line before is
} while (scur != inbuf.pos); instead of } while (inbuf.pos != scur);
Normally, the variable goes first.

    274                         acomp_walk_done_src(&walk, scur);
    275         } while (ret == 0);
    276 
    277 out:
    278         if (ret)
    279                 req->dlen = 0;
    280         else
    281                 req->dlen = total_out;
    282 
    283         crypto_acomp_unlock_stream_bh(s);
    284 
    285         return ret;
    286 }

regards,
dan carpenter




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux