From 72f58fe17adc3396a5c6826c5acf9a235b02b635 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Tue, 4 Jan 2022 12:20:30 +0800
Subject: [PATCH 33/53] uadk: optimize find_async_queue

No need to determine offset size before modulo.

Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
 wd_util.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/wd_util.c b/wd_util.c
index 676f475..9e96114 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1069,7 +1069,7 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
 	struct wd_env_config_per_numa *config_numa;
 	struct wd_ctx_range **ctx_table;
 	struct async_task_queue *head;
-	unsigned long offset;
+	unsigned long offset = 0;
 	int num = 0;
 	int i;
 
@@ -1093,10 +1093,8 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
 	for (i = 0; i < config_numa->op_type_num; i++) {
 		if (idx <= ctx_table[CTX_MODE_ASYNC][i].end &&
 		    idx >= ctx_table[CTX_MODE_ASYNC][i].begin) {
-			offset = idx - ctx_table[CTX_MODE_ASYNC][i].begin;
-			if (offset >= config_numa->async_poll_num)
-				offset = offset % config_numa->async_poll_num;
-
+			offset = (idx - ctx_table[CTX_MODE_ASYNC][i].begin) %
+				 config_numa->async_poll_num;
 			break;
 		}
 	}
-- 
2.25.1

