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

2016-09-15 Thread Horia Geanta Neag
On 9/15/2016 5:43 PM, SF Markus Elfring wrote:
> From: Markus Elfring 
> 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 
> ---
>  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


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

2016-09-15 Thread Horia Geanta Neag
On 9/15/2016 5:43 PM, SF Markus Elfring wrote:
> From: Markus Elfring 
> 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 
> ---
>  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


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

2016-09-15 Thread SF Markus Elfring
From: Markus Elfring 
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 
---
 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, , hashed_key,
-- 
2.10.0



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

2016-09-15 Thread SF Markus Elfring
From: Markus Elfring 
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 
---
 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, , hashed_key,
-- 
2.10.0