From: Weili Qian qianweili@huawei.com
If return type of the function 'async_module_init' is void, when function executes failed, the app continues to execute tasks. The process will be abnormal. Change 'async_module_init' type to int. If function executes failed, 0 is returned.
Signed-off-by: Weili Qian qianweili@huawei.com --- src/e_uadk.c | 16 +++++++++++++--- src/uadk_async.c | 9 +++++---- src/uadk_async.h | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/e_uadk.c b/src/e_uadk.c index 74dab39..ac4d738 100644 --- a/src/e_uadk.c +++ b/src/e_uadk.c @@ -238,8 +238,14 @@ static int uadk_init(ENGINE *e) return 1; }
- if (uadk_cipher || uadk_digest || uadk_rsa || uadk_dh || uadk_ecc) - async_module_init(); + if (uadk_cipher || uadk_digest || uadk_rsa || uadk_dh || uadk_ecc) { + ret = async_module_init(); + if (!ret) { + pthread_mutex_unlock(&uadk_engine_mutex); + fprintf(stderr, "failed to init async module!\n"); + return 0; + } + }
if (uadk_digest) uadk_e_digest_lock_init(); @@ -265,7 +271,11 @@ static int uadk_finish(ENGINE *e)
static void engine_init_child_at_fork_handler(void) { - async_module_init(); + int ret; + + ret = async_module_init(); + if (!ret) + fprintf(stderr, "failed to init child async module!\n"); }
#ifdef KAE diff --git a/src/uadk_async.c b/src/uadk_async.c index c98153b..e4eff43 100644 --- a/src/uadk_async.c +++ b/src/uadk_async.c @@ -335,7 +335,7 @@ static void *async_poll_process_func(void *args) return NULL; }
-void async_module_init(void) +int async_module_init(void) { pthread_t thread_id; pthread_attr_t thread_attr; @@ -343,11 +343,11 @@ void async_module_init(void) memset(&poll_queue, 0, sizeof(struct async_poll_queue));
if (pthread_mutex_init(&(poll_queue.async_task_mutex), NULL) < 0) - return; + return 0;
poll_queue.head = malloc(sizeof(struct async_poll_task) * ASYNC_QUEUE_TASK_NUM); if (poll_queue.head == NULL) - return; + return 0;
memset(poll_queue.head, 0, sizeof(struct async_poll_task) * ASYNC_QUEUE_TASK_NUM); @@ -367,8 +367,9 @@ void async_module_init(void) poll_queue.thread_id = thread_id; OPENSSL_atexit(async_poll_task_free);
- return; + return 1;
err: async_poll_task_free(); + return 0; } diff --git a/src/uadk_async.h b/src/uadk_async.h index 9836dbb..97b7d15 100644 --- a/src/uadk_async.h +++ b/src/uadk_async.h @@ -68,7 +68,7 @@ extern int async_setup_async_event_notification(struct async_op *op); extern int async_clear_async_event_notification(void); extern int async_pause_job(void *ctx, struct async_op *op, enum task_type type, int id); extern void async_register_poll_fn(int type, async_recv_t func); -extern void async_module_init(void); +extern int async_module_init(void); extern int async_wake_job(ASYNC_JOB *job); extern void async_free_poll_task(int id, bool is_cb); extern int async_get_free_task(int *id);