Fix the problem that some driver codes in uadk cause the driver to fail to load. In addition, solve the framework code for obtaining the current registration algorithm in the external interface.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- include/wd.h | 6 ++++++ wd.c | 18 +++++++++--------- wd_util.c | 21 ++++++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/include/wd.h b/include/wd.h index 1011817..0e67cad 100644 --- a/include/wd.h +++ b/include/wd.h @@ -584,11 +584,17 @@ bool wd_need_info(void); struct wd_capability { char alg_name[CRYPTO_MAX_ALG_NAME]; char drv_name[CRYPTO_MAX_ALG_NAME]; + bool available; int priority; + int calc_type;
struct wd_capability *next; };
+/** + * wd_get_alg_cap() - Get the algorithm information supported + * in the current system. + */ struct wd_capability *wd_get_alg_cap(void); void wd_release_alg_cap(struct wd_capability *head);
diff --git a/wd.c b/wd.c index 6f61f11..ddde38d 100644 --- a/wd.c +++ b/wd.c @@ -931,7 +931,7 @@ char *wd_ctx_get_dev_name(handle_t h_ctx) void wd_release_alg_cap(struct wd_capability *head) { struct wd_capability *cap_pnext = head; - struct wd_capability *cap_node = NULL; + struct wd_capability *cap_node;
while (cap_pnext) { cap_node = cap_pnext; @@ -948,30 +948,30 @@ struct wd_capability *wd_get_alg_cap(void) struct wd_alg_list *head = wd_get_alg_head(); struct wd_alg_list *pnext = head->next; struct wd_capability *cap_head = NULL; - struct wd_capability *cap_node = NULL; struct wd_capability *cap_pnext = NULL; - int i = 0; + struct wd_capability *cap_node;
while (pnext) { cap_node = calloc(1, sizeof(struct wd_capability)); - if (!cap_head) { + if (!cap_node) { WD_ERR("fail to alloc wd capability head\n"); goto alloc_err; }
strcpy(cap_node->alg_name, pnext->alg_name); strcpy(cap_node->drv_name, pnext->drv_name); + cap_node->available = pnext->available; cap_node->priority = pnext->priority; + cap_node->calc_type = pnext->calc_type; cap_node->next = NULL;
- cap_pnext->next = cap_node; - cap_pnext = cap_node; pnext = pnext->next; - if (i == 0) { + if (!cap_pnext) { cap_head = cap_node; - cap_pnext = cap_head; + cap_pnext = cap_node; } - i++; + cap_pnext->next = cap_node; + cap_pnext = cap_node; }
return cap_head; diff --git a/wd_util.c b/wd_util.c index 121b6d5..74505a0 100644 --- a/wd_util.c +++ b/wd_util.c @@ -90,7 +90,7 @@ struct acc_alg_item { };
static struct acc_alg_item alg_options[] = { - {"zlib", "zlib-deflate"}, + {"zlib", "zlib"}, {"gzip", "gzip"}, {"deflate", "deflate"}, {"lz77_zstd", "lz77_zstd"}, @@ -142,6 +142,10 @@ static struct acc_alg_item alg_options[] = { {"sha512", "digest"}, {"sha512-224", "digest"}, {"sha512-256", "digest"}, + {"cmac(aes)", "digest"}, + {"gmac(aes)", "digest"}, + {"xcbc-mac-96(aes)", "digest"}, + {"xcbc-prf-128(aes)", "digest"}, {"", ""} };
@@ -1962,7 +1966,7 @@ void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
driver->exit(priv); /* Ctx config just need clear once */ - if (driver->priority == UADK_ALG_HW) + if (driver->calc_type == UADK_ALG_HW) wd_clear_ctx_config(config);
if (driver->fallback) @@ -1970,7 +1974,7 @@ void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
if (priv) { free(priv); - priv = NULL; + *drv_priv = NULL; } }
@@ -2176,7 +2180,7 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) len = strlen(file_path) - 1; for (i = len; i >= 0; i--) { if (file_path[i] == '/') { - memset(&file_path[i], 0, PATH_MAX - i + 1); + memset(&file_path[i], 0, PATH_MAX - i); break; } } @@ -2312,6 +2316,9 @@ struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name) } } break; + default: + WD_ERR("task type error.\n"); + return NULL; }
return set_driver; @@ -2623,7 +2630,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) return -WD_EINVAL;
if (attrs->driver) - driver_type = attrs->driver->priority; + driver_type = attrs->driver->calc_type;
switch (driver_type) { case UADK_ALG_SOFT: @@ -2692,6 +2699,10 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) ret = alg_init_func(ctx_config, alg_sched); if (ret) goto out_pre_init; + break; + default: + WD_ERR("driver type error: %d\n", driver_type); + return -WD_EINVAL; }
return 0;