Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1484243

[PATCH 1/6] crypto-caamhash: Use kmalloc_array() in ahash_setkey()

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 1/6] crypto-caamhash: Use kmalloc_array() in ahash_setkey()
Date 2016-09-15 16:50 +0200
Message-ID <shG9b-8fB-7@gated-at.bofh.it> (permalink)
References <qEuGl-43C-5@gated-at.bofh.it> <shFZw-8bW-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 15 Sep 2016 11:20:09 +0200

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/crypto/caam/caamhash.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 9d7fc9e..f19df8f 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -525,8 +525,9 @@ static int ahash_setkey(struct crypto_ahash *ahash,
 #endif
 
 	if (keylen > blocksize) {
-		hashed_key = kmalloc(sizeof(u8) * digestsize, GFP_KERNEL |
-				     GFP_DMA);
+		hashed_key = kmalloc_array(digestsize,
+					   sizeof(*hashed_key),
+					   GFP_KERNEL | GFP_DMA);
 		if (!hashed_key)
 			return -ENOMEM;
 		ret = hash_digest_key(ctx, key, &keylen, hashed_key,
-- 
2.10.0

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

crypto-caamhash: Fine-tuning for several function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:40 +0200
  [PATCH 6/6] crypto-caamhash: Move common error handling code in two  functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:50 +0200
  [PATCH 1/6] crypto-caamhash: Use kmalloc_array() in ahash_setkey() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:50 +0200
    Re: [PATCH 1/6] crypto-caamhash: Use kmalloc_array() in  ahash_setkey() Horia Geanta Neag <horia.geanta@nxp.com> - 2016-09-16 04:00 +0200
  [PATCH 2/6] crypto-caamhash: Rename jump labels in ahash_setkey() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:50 +0200
  [PATCH 3/6] crypto-caamhash: Rename a jump label in five functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:50 +0200
  [PATCH 5/6] crypto-caamhash: Delete an unnecessary initialisation in  seven functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:50 +0200
  [PATCH 4/6] crypto-caamhash: Return a value directly in  caam_hash_cra_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 16:50 +0200
  Re: crypto-caamhash: Fine-tuning for several function implementations Horia Geanta Neag <horia.geanta@nxp.com> - 2016-09-15 22:10 +0200
  Re: crypto-caamhash: Fine-tuning for several function implementations Herbert Xu <herbert@gondor.apana.org.au> - 2016-09-22 12:50 +0200

csiph-web