diff mbox

crypto: caam: - Use kmemdup() function

Message ID 1523887514-17444-1-git-send-email-festevam@gmail.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Fabio Estevam April 16, 2018, 2:05 p.m. UTC
From: Fabio Estevam <fabio.estevam@nxp.com>

Use kmemdup() rather than duplicating its implementation.

Detected with Coccinelle script.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/crypto/caam/caampkc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Corentin Labbe April 16, 2018, 2:32 p.m. UTC | #1
On Mon, Apr 16, 2018 at 11:05:14AM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> Use kmemdup() rather than duplicating its implementation.
> 
> Detected with Coccinelle script.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> ---
>  drivers/crypto/caam/caampkc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
> index 979072b..c3518ce 100644
> --- a/drivers/crypto/caam/caampkc.c
> +++ b/drivers/crypto/caam/caampkc.c
> @@ -789,12 +789,10 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes)
>  	if (!*nbytes)
>  		return NULL;
>  
> -	val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL);
> +	val = kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL);
>  	if (!val)
>  		return NULL;
>  
> -	memcpy(val, buf, *nbytes);
> -
>  	return val;
>  }
>  

Hello

You could drop also the if (!val) return NULL

Regards
Horia Geanta April 16, 2018, 2:35 p.m. UTC | #2
On 4/16/2018 5:08 PM, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> Use kmemdup() rather than duplicating its implementation.
> 
> Detected with Coccinelle script.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> ---
>  drivers/crypto/caam/caampkc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
> index 979072b..c3518ce 100644
> --- a/drivers/crypto/caam/caampkc.c
> +++ b/drivers/crypto/caam/caampkc.c
> @@ -789,12 +789,10 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes)
>  	if (!*nbytes)
>  		return NULL;
>  
> -	val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL);
> +	val = kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL);
>  	if (!val)
>  		return NULL;
>  
> -	memcpy(val, buf, *nbytes);
> -
>  	return val;
>  }
Could be further simplified:
	return kmemdup(...);

Horia
diff mbox

Patch

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 979072b..c3518ce 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -789,12 +789,10 @@  static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes)
 	if (!*nbytes)
 		return NULL;
 
-	val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL);
+	val = kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL);
 	if (!val)
 		return NULL;
 
-	memcpy(val, buf, *nbytes);
-
 	return val;
 }