To avoid repeated free resource, wd_<alg>_common_uninit checks whether the 'priv' pointer exists. However, wd_<alg>_common_uninit does not return a value to the invoking function. As a result, the calling function continues to release resources.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 20 ++++++++++++++++---- wd_ecc.c | 20 ++++++++++++++++---- wd_rsa.c | 20 ++++++++++++++++---- 3 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index cb90093..546fb90 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -135,11 +135,11 @@ out_clear_ctx_config: return ret; }
-static void wd_dh_common_uninit(void) +static int wd_dh_common_uninit(void) { if (!wd_dh_setting.priv) { WD_ERR("invalid: repeat uninit dh!\n"); - return; + return -WD_EINVAL; }
/* uninit async request pool */ @@ -150,6 +150,8 @@ static void wd_dh_common_uninit(void) wd_alg_uninit_driver(&wd_dh_setting.config, wd_dh_setting.driver, &wd_dh_setting.priv); + + return 0; }
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -188,7 +190,12 @@ out_clear_init:
void wd_dh_uninit(void) { - wd_dh_common_uninit(); + int ret; + + ret = wd_dh_common_uninit(); + if (ret) + return; + wd_dh_close_driver(); wd_alg_clear_init(&wd_dh_setting.status); } @@ -287,7 +294,12 @@ out_clear_init:
void wd_dh_uninit2(void) { - wd_dh_common_uninit(); + int ret; + + ret = wd_dh_common_uninit(); + if (ret) + return; + wd_alg_attrs_uninit(&wd_dh_init_attrs); wd_alg_drv_unbind(wd_dh_setting.driver); wd_dlclose_drv(wd_dh_setting.dlh_list); diff --git a/wd_ecc.c b/wd_ecc.c index 3e90e95..0a9ebe0 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -201,11 +201,11 @@ out_clear_ctx_config: return ret; }
-static void wd_ecc_common_uninit(void) +static int wd_ecc_common_uninit(void) { if (!wd_ecc_setting.priv) { WD_ERR("invalid: repeat uninit ecc!\n"); - return; + return -WD_EINVAL; }
/* uninit async request pool */ @@ -216,6 +216,8 @@ static void wd_ecc_common_uninit(void) wd_alg_uninit_driver(&wd_ecc_setting.config, wd_ecc_setting.driver, &wd_ecc_setting.priv); + + return 0; }
int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -254,7 +256,12 @@ out_clear_init:
void wd_ecc_uninit(void) { - wd_ecc_common_uninit(); + int ret; + + ret = wd_ecc_common_uninit(); + if (ret) + return; + wd_ecc_close_driver(); wd_alg_clear_init(&wd_ecc_setting.status); } @@ -353,7 +360,12 @@ out_clear_init:
void wd_ecc_uninit2(void) { - wd_ecc_common_uninit(); + int ret; + + ret = wd_ecc_common_uninit(); + if (ret) + return; + wd_alg_attrs_uninit(&wd_ecc_init_attrs); wd_alg_drv_unbind(wd_ecc_setting.driver); wd_dlclose_drv(wd_ecc_setting.dlh_list); diff --git a/wd_rsa.c b/wd_rsa.c index b72ae23..382e831 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -176,11 +176,11 @@ out_clear_ctx_config: return ret; }
-static void wd_rsa_common_uninit(void) +static int wd_rsa_common_uninit(void) { if (!wd_rsa_setting.priv) { WD_ERR("invalid: repeat uninit rsa!\n"); - return; + return -WD_EINVAL; }
/* uninit async request pool */ @@ -191,6 +191,8 @@ static void wd_rsa_common_uninit(void) wd_alg_uninit_driver(&wd_rsa_setting.config, wd_rsa_setting.driver, &wd_rsa_setting.priv); + + return 0; }
int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -229,7 +231,12 @@ out_clear_init:
void wd_rsa_uninit(void) { - wd_rsa_common_uninit(); + int ret; + + ret = wd_rsa_common_uninit(); + if (ret) + return; + wd_rsa_close_driver(); wd_alg_clear_init(&wd_rsa_setting.status); } @@ -328,7 +335,12 @@ out_clear_init:
void wd_rsa_uninit2(void) { - wd_rsa_common_uninit(); + int ret; + + ret = wd_rsa_common_uninit(); + if (ret) + return; + wd_alg_attrs_uninit(&wd_rsa_init_attrs); wd_alg_drv_unbind(wd_rsa_setting.driver); wd_dlclose_drv(wd_rsa_setting.dlh_list);