lib/thread: return NULL when id is invalid before search form tailq

When call spdk_thread_get_by_id function to use thread->id to get thread point, if the id value is invaild, just return NULL before search from g_threads tailq.

Signed-off-by: sunshihao <sunshihao@huawei.com>
Change-Id: Ic6c35d2c2b5093c9b513618742b8b9835599ba63
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5031
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
sunshihao520 2020-11-06 09:39:09 +08:00 committed by Jim Harris
parent 57833a5dff
commit 33e1f4b0e2

View File

@ -835,17 +835,18 @@ spdk_thread_get_by_id(uint64_t id)
{
struct spdk_thread *thread;
if (id == 0 || id >= g_thread_id) {
SPDK_ERRLOG("invalid thread id: %" PRIu64 ".\n", id);
return NULL;
}
pthread_mutex_lock(&g_devlist_mutex);
TAILQ_FOREACH(thread, &g_threads, tailq) {
if (thread->id == id) {
pthread_mutex_unlock(&g_devlist_mutex);
return thread;
break;
}
}
pthread_mutex_unlock(&g_devlist_mutex);
return NULL;
return thread;
}
int