2006-09-26 11:05:45

by Eric Sesterhenn

[permalink] [raw]
Subject: Dead code in crypto/tcrypt.c

hi,

the following commit added some code in test_hash_cycles() which coverity flags as dead code.
http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=e9d41164e2fdd897fe4520c2079ea0000f6e0ec3

The culprit are the following lines:


for (i = 0; i < 4; i++) {
- crypto_digest_init(tfm);
+ ret = crypto_hash_init(desc);
+ if (ret)
+ goto out;
for (pcount = 0; pcount < blen; pcount += plen) {
sg_set_buf(sg, p + pcount, plen);
- crypto_digest_update(tfm, sg, 1);
+ ret = crypto_hash_update(desc, sg, plen);
+ if (ret)
+ goto out;
}
- crypto_digest_final(tfm, out);
+ crypto_hash_final(desc, out);
+ if (ret)
+ goto out;
}

We check ret before the for loop, and inside it, and
there is no way it can change in between. Are we missing
to assign the return value of crypto_hash_final() to ret?

Greetings, Eric



2006-09-27 11:09:31

by Herbert Xu

[permalink] [raw]
Subject: Re: Dead code in crypto/tcrypt.c

Eric Sesterhenn <[email protected]> wrote:
>
> the following commit added some code in test_hash_cycles() which coverity flags as dead code.
> http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=e9d41164e2fdd897fe4520c2079ea0000f6e0ec3

Thanks for spotting this. I've put the following patch
into the tree.
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 8330742..587a135 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -646,7 +646,7 @@ static int test_hash_cycles(struct hash_
if (ret)
goto out;
}
- crypto_hash_final(desc, out);
+ ret = crypto_hash_final(desc, out);
if (ret)
goto out;
}