diff mbox

[v2] crypto: caam: - Use kmemdup() function

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

Commit Message

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

Use kmemdup() rather than duplicating its implementation.

By usign kmemdup() we can also get rid of the 'val' variable.

Detected with Coccinelle script.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
Changes since v1:
- Drop the val variable and return kmemdup() directly.

 drivers/crypto/caam/caampkc.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

Comments

Horia Geanta April 17, 2018, 4:36 a.m. UTC | #1
On 4/16/2018 7:07 PM, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> Use kmemdup() rather than duplicating its implementation.
> 
> By usign kmemdup() we can also get rid of the 'val' variable.
> 
> Detected with Coccinelle script.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Thanks,
Horia
Herbert Xu April 20, 2018, 5:06 p.m. UTC | #2
On Mon, Apr 16, 2018 at 01:05:01PM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> Use kmemdup() rather than duplicating its implementation.
> 
> By usign kmemdup() we can also get rid of the 'val' variable.
> 
> Detected with Coccinelle script.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>

Patch applied.  Thanks.
diff mbox

Patch

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 979072b..6f99013 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -783,19 +783,12 @@  static u8 *caam_read_rsa_crt(const u8 *ptr, size_t nbytes, size_t dstlen)
  */
 static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes)
 {
-	u8 *val;
 
 	caam_rsa_drop_leading_zeros(&buf, nbytes);
 	if (!*nbytes)
 		return NULL;
 
-	val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL);
-	if (!val)
-		return NULL;
-
-	memcpy(val, buf, *nbytes);
-
-	return val;
+	return kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL);
 }
 
 static int caam_rsa_check_key_length(unsigned int len)