From 752fa1ca27f7dee31bcaebc50c3a02ce16fcd3ad Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 28 Jun 2019 13:15:16 +0900 Subject: [PATCH] thread: Assign not pointer but instance of spdk_cpuset in struct spdk_thread This will reduce potential malloc failures. Change-Id: Ie67554fec877e33bbd1044fc61eb4d79df306168 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459717 Tested-by: SPDK CI Jenkins Reviewed-by: Paul Luse Reviewed-by: Changpeng Liu --- lib/thread/thread.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 11b6f80a3a..f646410103 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -109,7 +109,7 @@ struct spdk_thread { bool exit; - struct spdk_cpuset *cpumask; + struct spdk_cpuset cpumask; uint64_t tsc_last; struct spdk_thread_stats stats; @@ -228,8 +228,6 @@ _free_thread(struct spdk_thread *thread) TAILQ_REMOVE(&g_threads, thread, tailq); pthread_mutex_unlock(&g_devlist_mutex); - spdk_cpuset_free(thread->cpumask); - msg = SLIST_FIRST(&thread->msg_cache); while (msg != NULL) { SLIST_REMOVE_HEAD(&thread->msg_cache, link); @@ -260,17 +258,10 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask) return NULL; } - thread->cpumask = spdk_cpuset_alloc(); - if (!thread->cpumask) { - free(thread); - SPDK_ERRLOG("Unable to allocate memory for CPU mask\n"); - return NULL; - } - if (cpumask) { - spdk_cpuset_copy(thread->cpumask, cpumask); + spdk_cpuset_copy(&thread->cpumask, cpumask); } else { - spdk_cpuset_negate(thread->cpumask); + spdk_cpuset_negate(&thread->cpumask); } TAILQ_INIT(&thread->io_channels); @@ -284,7 +275,6 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask) thread->messages = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY); if (!thread->messages) { SPDK_ERRLOG("Unable to allocate memory for message ring\n"); - spdk_cpuset_free(thread->cpumask); free(thread); return NULL; } @@ -367,7 +357,7 @@ spdk_thread_get_ctx(struct spdk_thread *thread) struct spdk_cpuset * spdk_thread_get_cpumask(struct spdk_thread *thread) { - return thread->cpumask; + return &thread->cpumask; } struct spdk_thread *