Skip to contentSkip to conversation

crypto: nx - add hardware 842 crypto comp alg

PATCH Applied Dan Carpenter 3 participants 4 messages May 14, 2015 – May 18, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hello Dan Streetman,

This is a semi-automatic email about new static checker warnings.

The patch ed70b479c2c0: "crypto: nx - add hardware 842 crypto comp alg" from May 7, 2015, leads to the following Smatch complaint:

drivers/crypto/nx/nx-842-crypto.c:301 nx842_crypto_compress()
warn: variable dereferenced before check 'tfm' (see line 292)

drivers/crypto/nx/nx-842-crypto.c
288 static int nx842_crypto_compress(struct crypto_tfm *tfm,
289 const u8 *src, unsigned int slen,
290 u8 *dst, unsigned int *dlen)
291 {

   292		struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
                                                              ^^^

Dereference.

293 struct nx842_crypto_header *hdr = &ctx->header;
294 struct nx842_crypto_param p;
295 struct nx842_constraints c;
296 unsigned int groups, hdrsize, h;
297 int ret, n;
298 bool add_header;
299 u16 ignore = 0;
300
301 if (!tfm || !src || !slen || !dst || !dlen)

                     ^^^

Checked for NULL.

302 return -EINVAL;
303

The decompress function has the same warning:

	drivers/crypto/nx/nx-842-crypto.c:486 nx842_crypto_decompress()
	warn: variable dereferenced before check 'tfm' (see line 478)

regards,
dan carpenter

maintainer
#1 lore raw
Quoted 29 lines · Dan Carpenter

Hello Dan Streetman,

This is a semi-automatic email about new static checker warnings.

The patch ed70b479c2c0: "crypto: nx - add hardware 842 crypto comp alg" from May 7, 2015, leads to the following Smatch complaint:

drivers/crypto/nx/nx-842-crypto.c:301 nx842_crypto_compress()
warn: variable dereferenced before check 'tfm' (see line 292)

drivers/crypto/nx/nx-842-crypto.c
288 static int nx842_crypto_compress(struct crypto_tfm *tfm,
289 const u8 *src, unsigned int slen,
290 u8 *dst, unsigned int *dlen)
291 {

  292          struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
                                                             ^^^

Dereference.

  293          struct nx842_crypto_header *hdr = &ctx->header;
  294          struct nx842_crypto_param p;
  295          struct nx842_constraints c;
  296          unsigned int groups, hdrsize, h;
  297          int ret, n;
  298          bool add_header;
  299          u16 ignore = 0;
  300  
  301          if (!tfm || !src || !slen || !dst || !dlen)
                    ^^^
Quoted 4 lines

Checked for NULL.

302 return -EINVAL;
303

tfm can never be NULL so this should be removed.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw

PATCH 1/1 crypto: remove 842-nx null checks

Remove the null checks for tfm, src, slen, dst, dlen; tfm will never be null and the other fields are always expected to be set correctly.

---
 drivers/crypto/nx/nx-842-crypto.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/crypto/nx/nx-842-crypto.c +0 -6
index cb177c3..2ffa103 100644
@@ -298,9 +298,6 @@ static int nx842_crypto_compress(struct crypto_tfm *tfm,
 	bool add_header;
 	u16 ignore = 0;
 
-	if (!tfm || !src || !slen || !dst || !dlen)
-		return -EINVAL;
-
 	p.in = (u8 *)src;
 	p.iremain = slen;
 	p.out = dst;
@@ -483,9 +480,6 @@ static int nx842_crypto_decompress(struct crypto_tfm *tfm,
 	u16 ignore = 0;
 	bool usehw = true;
 
-	if (!tfm || !src || !slen || !dst || !dlen)
-		return -EINVAL;
-
 	p.in = (u8 *)src;
 	p.iremain = slen;
 	p.out = dst;
Signature · 1 line
2.1.0
maintainer Applied
#3 lore raw

Re: [PATCH] crypto: remove 842-nx null checks

Quoted 5 lines · Dan Streetman

Remove the null checks for tfm, src, slen, dst, dlen; tfm will never be null and the other fields are always expected to be set correctly.

Applied.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt