From 1d20eaf8c0829531ab5cb4fc8ecd4142147b482d Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Wed, 9 Mar 2022 01:30:51 +0000
Subject: [PATCH 084/109] uadk: bugfix segment fault when uninitializing

When the initialization of each alg driver failed,
the wd_<alg>_setting.priv should be set to NULL.
Otherwise there will be segment fault when
uninitializing the alg driver.

Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
 wd_aead.c   | 1 +
 wd_cipher.c | 1 +
 wd_comp.c   | 1 +
 wd_dh.c     | 1 +
 wd_digest.c | 1 +
 wd_ecc.c    | 1 +
 wd_rsa.c    | 1 +
 7 files changed, 7 insertions(+)

diff --git a/wd_aead.c b/wd_aead.c
index a78f152..7df8e80 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -458,6 +458,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_aead_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_aead_setting.pool);
 out_sched:
diff --git a/wd_cipher.c b/wd_cipher.c
index 8daac0f..afd8c4d 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -299,6 +299,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_cipher_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_cipher_setting.pool);
 out_sched:
diff --git a/wd_comp.c b/wd_comp.c
index 886e6fc..8d0c603 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -145,6 +145,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_comp_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_comp_setting.pool);
 out_sched:
diff --git a/wd_dh.c b/wd_dh.c
index 841a126..f5d70a2 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -145,6 +145,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_dh_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_dh_setting.pool);
 out_sched:
diff --git a/wd_digest.c b/wd_digest.c
index 21c3876..06774be 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -220,6 +220,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_digest_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_digest_setting.pool);
 out_sched:
diff --git a/wd_ecc.c b/wd_ecc.c
index a9994b2..d925bc3 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -199,6 +199,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_ecc_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_ecc_setting.pool);
 out_sched:
diff --git a/wd_rsa.c b/wd_rsa.c
index 4c8fd71..8fc405f 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -185,6 +185,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
 
 out_init:
 	free(priv);
+	wd_rsa_setting.priv = NULL;
 out_priv:
 	wd_uninit_async_request_pool(&wd_rsa_setting.pool);
 out_sched:
-- 
2.27.0

