From d2baa1092ed8d8dbc11ea9dfb47848e933a4da46 Mon Sep 17 00:00:00 2001 From: Park Ju Hyung Date: Wed, 18 Mar 2020 20:23:03 +0900 Subject: [PATCH] kthread: use buffer from the stack space struct kthread_create_info is small enough to fit perfectly under the stack space. Signed-off-by: Park Ju Hyung Signed-off-by: Adam W. Willis --- kernel/kthread.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index e7a8797366a6..ac7f7cfc5729 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -302,18 +302,15 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), { DECLARE_COMPLETION_ONSTACK(done); struct task_struct *task; - struct kthread_create_info *create = kmalloc(sizeof(*create), - GFP_KERNEL); + struct kthread_create_info create; - if (!create) - return ERR_PTR(-ENOMEM); - create->threadfn = threadfn; - create->data = data; - create->node = node; - create->done = &done; + create.threadfn = threadfn; + create.data = data; + create.node = node; + create.done = &done; spin_lock(&kthread_create_lock); - list_add_tail(&create->list, &kthread_create_list); + list_add_tail(&create.list, &kthread_create_list); spin_unlock(&kthread_create_lock); wake_up_process(kthreadd_task); @@ -328,7 +325,7 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), * calls complete(), leave the cleanup of this structure to * that thread. */ - if (xchg(&create->done, NULL)) + if (xchg(&create.done, NULL)) return ERR_PTR(-EINTR); /* * kthreadd (or new kernel thread) will call complete() @@ -336,7 +333,7 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), */ wait_for_completion(&done); } - task = create->result; + task = create.result; if (!IS_ERR(task)) { static const struct sched_param param = { .sched_priority = 0 }; char name[TASK_COMM_LEN]; @@ -354,7 +351,6 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), sched_setscheduler_nocheck(task, SCHED_NORMAL, ¶m); set_cpus_allowed_ptr(task, cpu_all_mask); } - kfree(create); return task; }