From 17bc4f46411541e725d30ec76693982765a96114 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 27 Dec 2021 09:52:00 +0800
Subject: [PATCH 12/28] uadk: fix error of wd_get_avail_ctx return value

When wd_get_avail_ctx return negative value,
wd should not use this device.

Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
 wd.c      | 3 ++-
 wd_util.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/wd.c b/wd.c
index 838efa7..2bb2fdd 100644
--- a/wd.c
+++ b/wd.c
@@ -675,7 +675,8 @@ struct uacce_dev *wd_get_accel_dev(const char *alg_name)
 	while (list) {
 		tmp = numa_distance(node, list->dev->numa_id);
 		ctx_num = wd_get_avail_ctx(list->dev);
-		if ((dis > tmp && ctx_num) || (dis == tmp && ctx_num > max)) {
+		if ((dis > tmp && ctx_num > 0) ||
+		    (dis == tmp && ctx_num > max)) {
 			dev = list->dev;
 			dis = tmp;
 			max = ctx_num;
diff --git a/wd_util.c b/wd_util.c
index c973eff..3c1fd26 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -846,7 +846,7 @@ static handle_t request_ctx_on_numa(struct wd_env_config_per_numa *config)
 	for (i = 0; i < config->dev_num; i++) {
 		dev = config->dev + i;
 		ctx_num = wd_get_avail_ctx(dev);
-		if (!ctx_num)
+		if (ctx_num <= 0)
 			continue;
 
 		h_ctx = wd_request_ctx(dev);
-- 
2.31.1

