Commit 33e1f4b0 authored by sunshihao520's avatar sunshihao520 Committed by Jim Harris
Browse files

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: default avatarsunshihao <sunshihao@huawei.com>
Change-Id: Ic6c35d2c2b5093c9b513618742b8b9835599ba63
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5031


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 57833a5d
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -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