Add null pointer check to avoid segment errors.
Signed-off-by: Qi Tao taoqi10@huawei.com --- drv/hash_mb/hash_mb.c | 6 +++--- drv/hisi_comp.c | 8 +++----- drv/hisi_dae.c | 6 +++--- drv/hisi_hpre.c | 8 +++----- drv/hisi_sec.c | 8 +++----- drv/isa_ce_sm3.c | 6 +++--- drv/isa_ce_sm4.c | 6 +++--- 7 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c index e4a9564f..9ad36b81 100644 --- a/drv/hash_mb/hash_mb.c +++ b/drv/hash_mb/hash_mb.c @@ -217,11 +217,11 @@ static int hash_mb_init(struct wd_alg_driver *drv, void *conf)
static void hash_mb_exit(struct wd_alg_driver *drv) { - struct hash_mb_ctx *priv = (struct hash_mb_ctx *)drv->priv; - - if (!priv) + if(!drv || !drv->priv) return;
+ struct hash_mb_ctx *priv = (struct hash_mb_ctx *)drv->priv; + hash_mb_queue_uninit(&priv->config, priv->config.ctx_num); free(priv); drv->priv = NULL; diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 4c8e18b2..c5569986 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -835,16 +835,14 @@ out:
static void hisi_zip_exit(struct wd_alg_driver *drv) { + if(!drv || !drv->priv) + return; + struct hisi_zip_ctx *priv = (struct hisi_zip_ctx *)drv->priv; struct wd_ctx_config_internal *config; handle_t h_qp; __u32 i;
- if (!priv) { - /* return if already exit */ - return; - } - config = &priv->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c index 09d23874..864d21ba 100644 --- a/drv/hisi_dae.c +++ b/drv/hisi_dae.c @@ -1604,14 +1604,14 @@ out:
static void dae_exit(struct wd_alg_driver *drv) { + if(!drv || !drv->priv) + return; + struct hisi_dae_ctx *priv = (struct hisi_dae_ctx *)drv->priv; struct wd_ctx_config_internal *config; handle_t h_qp; __u32 i;
- if (!priv) - return; - config = &priv->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 37bb5ee1..313cdcc8 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -583,16 +583,14 @@ static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
static void hpre_exit(struct wd_alg_driver *drv) { + if(!drv || !drv->priv) + return; + struct hisi_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv; struct wd_ctx_config_internal *config; handle_t h_qp; __u32 i;
- if (!priv) { - /* return if already exit */ - return; - } - config = &priv->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 0a1bcc1e..63775869 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -3102,16 +3102,14 @@ out:
static void hisi_sec_exit(struct wd_alg_driver *drv) { + if(!drv || !drv->priv) + return; + struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv; struct wd_ctx_config_internal *config; handle_t h_qp; __u32 i;
- if (!priv) { - /* return if already exit */ - return; - } - config = &priv->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index 99cd6404..54c2a9e7 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -392,11 +392,11 @@ static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf)
static void sm3_ce_drv_exit(struct wd_alg_driver *drv) { - struct sm3_ce_drv_ctx *sctx = (struct sm3_ce_drv_ctx *)drv->priv; - - if (!sctx) + if(!drv || !drv->priv) return;
+ struct sm3_ce_drv_ctx *sctx = (struct sm3_ce_drv_ctx *)drv->priv; + free(sctx); drv->priv = NULL; } diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 3404465b..5e448fa0 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -53,11 +53,11 @@ static int isa_ce_init(struct wd_alg_driver *drv, void *conf)
static void isa_ce_exit(struct wd_alg_driver *drv) { - struct sm4_ce_drv_ctx *sctx = (struct sm4_ce_drv_ctx *)drv->priv; - - if (!sctx) + if(!drv || !drv->priv) return;
+ struct sm4_ce_drv_ctx *sctx = (struct sm4_ce_drv_ctx *)drv->priv; + free(sctx); drv->priv = NULL; }