From a1d263fc8bc5aa87a9287b7d5a5fb717a1556bc5 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 15 Feb 2022 11:49:49 +0800
Subject: [PATCH 56/64] uadk: optimize algorithm initialization

malloc and memset can be replaced by calloc.

Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
 wd_aead.c   | 3 +--
 wd_dh.c     | 4 +---
 wd_digest.c | 4 +---
 wd_ecc.c    | 4 +---
 wd_rsa.c    | 4 +---
 5 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/wd_aead.c b/wd_aead.c
index 82a1f97..d8581db 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -441,12 +441,11 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
 	}
 
 	/* init ctx related resources in specific driver */
-	priv = malloc(wd_aead_setting.driver->drv_ctx_size);
+	priv = calloc(1, wd_aead_setting.driver->drv_ctx_size);
 	if (!priv) {
 		ret = -WD_ENOMEM;
 		goto out_priv;
 	}
-	memset(priv, 0, wd_aead_setting.driver->drv_ctx_size);
 	wd_aead_setting.priv = priv;
 
 	ret = wd_aead_setting.driver->init(&wd_aead_setting.config, priv);
diff --git a/wd_dh.c b/wd_dh.c
index 1784099..b361d5d 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -127,14 +127,12 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
 	}
 
 	/* initialize ctx related resources in specific driver */
-	priv = malloc(wd_dh_setting.driver->drv_ctx_size);
+	priv = calloc(1, wd_dh_setting.driver->drv_ctx_size);
 	if (!priv) {
-		WD_ERR("failed to calloc drv ctx\n");
 		ret = -WD_ENOMEM;
 		goto out_priv;
 	}
 
-	memset(priv, 0, wd_dh_setting.driver->drv_ctx_size);
 	wd_dh_setting.priv = priv;
 	ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv,
 					 wd_dh_setting.driver->alg_name);
diff --git a/wd_digest.c b/wd_digest.c
index d4e710d..1c05851 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -203,13 +203,11 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
 	}
 
 	/* init ctx related resources in specific driver */
-	priv = malloc(wd_digest_setting.driver->drv_ctx_size);
+	priv = calloc(1, wd_digest_setting.driver->drv_ctx_size);
 	if (!priv) {
-		WD_ERR("failed to alloc digest driver ctx!\n");
 		ret = -WD_ENOMEM;
 		goto out_priv;
 	}
-	memset(priv, 0, wd_digest_setting.driver->drv_ctx_size);
 	wd_digest_setting.priv = priv;
 
 	ret = wd_digest_setting.driver->init(&wd_digest_setting.config, priv);
diff --git a/wd_ecc.c b/wd_ecc.c
index e324473..89566ea 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -181,14 +181,12 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
 	}
 
 	/* initialize ctx related resources in specific driver */
-	priv = malloc(wd_ecc_setting.driver->drv_ctx_size);
+	priv = calloc(1, wd_ecc_setting.driver->drv_ctx_size);
 	if (!priv) {
-		WD_ERR("failed to calloc drv ctx\n");
 		ret = -WD_ENOMEM;
 		goto out_priv;
 	}
 
-	memset(priv, 0, wd_ecc_setting.driver->drv_ctx_size);
 	wd_ecc_setting.priv = priv;
 	ret = wd_ecc_setting.driver->init(&wd_ecc_setting.config, priv,
 					  wd_ecc_setting.driver->alg_name);
diff --git a/wd_rsa.c b/wd_rsa.c
index 1f911b4..2e61927 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -167,14 +167,12 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
 	}
 
 	/* initialize ctx related resources in specific driver */
-	priv = malloc(wd_rsa_setting.driver->drv_ctx_size);
+	priv = calloc(1, wd_rsa_setting.driver->drv_ctx_size);
 	if (!priv) {
-		WD_ERR("failed to calloc drv ctx\n");
 		ret = -WD_ENOMEM;
 		goto out_priv;
 	}
 
-	memset(priv, 0, wd_rsa_setting.driver->drv_ctx_size);
 	wd_rsa_setting.priv = priv;
 	ret = wd_rsa_setting.driver->init(&wd_rsa_setting.config, priv,
 					  wd_rsa_setting.driver->alg_name);
-- 
2.25.1

