Use use_env to check whether environment variables are used.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- Makefile.am | 1 + wd_util.c | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 601a20d..a4bb470 100644 --- a/Makefile.am +++ b/Makefile.am @@ -120,6 +120,7 @@ libwd_crypto_la_DEPENDENCIES= libwd.la
libhisi_zip_la_LIBADD= -lwd -ldl libhisi_zip_la_LDFLAGS=$(UADK_VERSION) +libhisi_zip_la_DEPENDENCIES= libwd.la
libhisi_sec_la_LIBADD= -lwd -lwd_crypto libhisi_sec_la_LDFLAGS=$(UADK_VERSION) diff --git a/wd_util.c b/wd_util.c index b6f65dd..8286092 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2012,6 +2012,10 @@ static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section, return -WD_EINVAL;
ctx_section = index(section, ':'); + if (!ctx_section) { + WD_ERR("invalid: ctx section got wrong format: %s!\n", section); + return -WD_EINVAL; + } ctx_section++; ret = parse_num_on_numa(ctx_section, &ctx_num, &node); if (ret) @@ -2036,20 +2040,17 @@ static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section, return -WD_EINVAL; }
-/* return 0 for success, return 1 for env unset, others failed */ -static int wd_env_set_ctx_nums(const char *name, struct wd_ctx_nums *ctx_nums, __u32 size) +/* return 0 for success, others failed */ +static int wd_env_set_ctx_nums(const char *name, const char *var_s, + struct wd_ctx_nums *ctx_nums, __u32 size) { - char *left, *section, *start, *var_s; + char *left, *section, *start; int is_comp; - int ret = 1; + int ret = 0;
/* COMP environment variable's format is different, mark it */ is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1;
- var_s = secure_getenv(name); - if (!var_s || !strlen(var_s)) - return ret; - start = strdup(var_s); if (!start) return -WD_ENOMEM; @@ -2072,19 +2073,21 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, const char *env_name, int max_op_type) { + const char *var_s; + int use_env = 0; int i, ret;
- ret = wd_env_set_ctx_nums(env_name, ctx_params->ctx_set_num, max_op_type); - if (ret < 0) { - WD_ERR("fail to init ctx nums from %s!\n", env_name); - return -WD_EINVAL; + var_s = secure_getenv(env_name); + if (var_s && strlen(var_s)) { + ret = wd_env_set_ctx_nums(env_name, var_s, ctx_params->ctx_set_num, max_op_type); + if (ret < 0) { + WD_ERR("fail to init ctx nums from %s!\n", env_name); + return -WD_EINVAL; + } + use_env = 1; }
- /** - * Only if environment variable is not parsed and user's params are exist, - * set ctx_params from user's params, otherwise set it from env or driver. - */ - if (!ret || !user_ctx_params) { + if (use_env || !user_ctx_params) { ctx_params->bmp = NULL; ctx_params->op_type_num = driver->op_type_num; if (ctx_params->op_type_num > max_op_type) {