From f43d50084550042f053de2dcce03d91d5f8b040a Mon Sep 17 00:00:00 2001 From: Weili Qian Date: Tue, 26 Jul 2022 10:58:56 +0800 Subject: [PATCH 57/57] engine: fix function type 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 --- 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 1b95284..77612d7 100644 --- a/src/e_uadk.c +++ b/src/e_uadk.c @@ -239,8 +239,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(); @@ -266,7 +272,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 11d624c..3f2e1db 100644 --- a/src/uadk_async.c +++ b/src/uadk_async.c @@ -336,7 +336,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; @@ -344,11 +344,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); @@ -368,8 +368,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 78f7a21..9bae3f4 100644 --- a/src/uadk_async.h +++ b/src/uadk_async.h @@ -69,7 +69,7 @@ int async_setup_async_event_notification(struct async_op *op); int async_clear_async_event_notification(void); int async_pause_job(void *ctx, struct async_op *op, enum task_type type, int id); void async_register_poll_fn(int type, async_recv_t func); -void async_module_init(void); +int async_module_init(void); int async_wake_job(ASYNC_JOB *job); void async_free_poll_task(int id, bool is_cb); int async_get_free_task(int *id); -- 2.27.0