[PATCH] crypto: iaa - Use kmemdup() instead of kzalloc() and memcpy()

Thorsten Blum posted 1 patch 1 year, 7 months ago
drivers/crypto/intel/iaa/iaa_crypto_main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH] crypto: iaa - Use kmemdup() instead of kzalloc() and memcpy()
Posted by Thorsten Blum 1 year, 7 months ago
Fixes the following two Coccinelle/coccicheck warnings reported by
memdup.cocci:

	iaa_crypto_main.c:350:19-26: WARNING opportunity for kmemdup
	iaa_crypto_main.c:358:18-25: WARNING opportunity for kmemdup

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c
index b2191ade9011..7635fbebe52f 100644
--- a/drivers/crypto/intel/iaa/iaa_crypto_main.c
+++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c
@@ -347,18 +347,16 @@ int add_iaa_compression_mode(const char *name,
 		goto free;
 
 	if (ll_table) {
-		mode->ll_table = kzalloc(ll_table_size, GFP_KERNEL);
+		mode->ll_table = kmemdup(ll_table, ll_table_size, GFP_KERNEL);
 		if (!mode->ll_table)
 			goto free;
-		memcpy(mode->ll_table, ll_table, ll_table_size);
 		mode->ll_table_size = ll_table_size;
 	}
 
 	if (d_table) {
-		mode->d_table = kzalloc(d_table_size, GFP_KERNEL);
+		mode->d_table = kmemdup(d_table, d_table_size, GFP_KERNEL);
 		if (!mode->d_table)
 			goto free;
-		memcpy(mode->d_table, d_table, d_table_size);
 		mode->d_table_size = d_table_size;
 	}
 
-- 
2.44.0
Re: [PATCH] crypto: iaa - Use kmemdup() instead of kzalloc() and memcpy()
Posted by Herbert Xu 1 year, 7 months ago
On Thu, May 02, 2024 at 05:33:39PM +0200, Thorsten Blum wrote:
> Fixes the following two Coccinelle/coccicheck warnings reported by
> memdup.cocci:
> 
> 	iaa_crypto_main.c:350:19-26: WARNING opportunity for kmemdup
> 	iaa_crypto_main.c:358:18-25: WARNING opportunity for kmemdup
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  drivers/crypto/intel/iaa/iaa_crypto_main.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] crypto: iaa - Use kmemdup() instead of kzalloc() and memcpy()
Posted by Tom Zanussi 1 year, 7 months ago
Hi Thorsten,

On Thu, 2024-05-02 at 17:33 +0200, Thorsten Blum wrote:
> Fixes the following two Coccinelle/coccicheck warnings reported by
> memdup.cocci:
> 
>         iaa_crypto_main.c:350:19-26: WARNING opportunity for kmemdup
>         iaa_crypto_main.c:358:18-25: WARNING opportunity for kmemdup
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  drivers/crypto/intel/iaa/iaa_crypto_main.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c
> index b2191ade9011..7635fbebe52f 100644
> --- a/drivers/crypto/intel/iaa/iaa_crypto_main.c
> +++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c
> @@ -347,18 +347,16 @@ int add_iaa_compression_mode(const char *name,
>                 goto free;
>  
>         if (ll_table) {
> -               mode->ll_table = kzalloc(ll_table_size, GFP_KERNEL);
> +               mode->ll_table = kmemdup(ll_table, ll_table_size, GFP_KERNEL);
>                 if (!mode->ll_table)
>                         goto free;
> -               memcpy(mode->ll_table, ll_table, ll_table_size);
>                 mode->ll_table_size = ll_table_size;
>         }
>  
>         if (d_table) {
> -               mode->d_table = kzalloc(d_table_size, GFP_KERNEL);
> +               mode->d_table = kmemdup(d_table, d_table_size, GFP_KERNEL);
>                 if (!mode->d_table)
>                         goto free;
> -               memcpy(mode->d_table, d_table, d_table_size);
>                 mode->d_table_size = d_table_size;
>         }
>  

Looks good, thanks for the cleanup.

Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com>