Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1484642
| From | Horia Geanta Neag <horia.geanta@nxp.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/6] crypto-caamhash: Use kmalloc_array() in ahash_setkey() |
| Date | 2016-09-16 04:00 +0200 |
| Message-ID | <shQBz-6pI-3@gated-at.bofh.it> (permalink) |
| References | <qEuGl-43C-5@gated-at.bofh.it> <shFZw-8bW-27@gated-at.bofh.it> <shG9b-8fB-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 9/15/2016 5:43 PM, SF Markus Elfring wrote:
> 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);
While correct, instead I would go with kmalloc() and get rid of sizeof(u8).
Horia
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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