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 <qkrwngud825@gmail.com>
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
This commit is contained in:
Park Ju Hyung 2020-03-18 20:23:03 +09:00 committed by spakkkk
parent 518acbdb88
commit d2baa1092e

View File

@ -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, &param);
set_cpus_allowed_ptr(task, cpu_all_mask);
}
kfree(create);
return task;
}