INSTR driver should alloc and free private ctx by himself.
Signed-off-by: Qi Tao taoqi10@huawei.com --- drv/isa_ce_sm4.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index e9378930..b81362c8 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -34,20 +34,31 @@ static int isa_ce_init(struct wd_alg_driver *drv, void *conf) { struct wd_ctx_config_internal *config = conf; - struct sm4_ce_drv_ctx *sctx = drv->priv; + struct sm4_ce_drv_ctx *sctx = (struct sm4_ce_drv_ctx *)drv->priv;
- /* Fallback init is NULL */ - if (!drv || !conf) - return 0; + /* return if already inited */ + if (sctx) + return WD_SUCCESS; + + sctx = malloc(sizeof(struct sm4_ce_drv_ctx)); + if (!sctx) + return -WD_EINVAL;
config->epoll_en = 0; memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
- return 0; + return WD_SUCCESS; }
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) + return; + + free(sctx); + drv->priv = NULL; }
/* increment upper 96 bits of 128-bit counter by 1 */