From c7bd5301bac728b727d112376423538e860ee6be Mon Sep 17 00:00:00 2001 From: EurusHomles-zH Date: Tue, 11 Jul 2023 15:04:33 +0800 Subject: [PATCH] Description:optimize task struct usage Signed-off-by: EurusHomles-zH --- drivers/staging/hungtask/hungtask_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/staging/hungtask/hungtask_user.c b/drivers/staging/hungtask/hungtask_user.c index 39b0b1bd5035..4d4627132a37 100644 --- a/drivers/staging/hungtask/hungtask_user.c +++ b/drivers/staging/hungtask/hungtask_user.c @@ -38,13 +38,18 @@ static void htuser_show_task(int pid) { struct task_struct *p = NULL; + rcu_read_lock(); p = pid_task(find_vpid(pid), PIDTYPE_PID); - if (p == NULL) { + if(p) + get_task_struct(p); + rcu_read_unlock(); + if (!p) { pr_err("can not find pid %d\n", pid); return; } if (p->flags & PF_FROZEN) { + put_task_struct(p); pr_info("process %d is frozen\n", pid); return; } @@ -53,6 +58,7 @@ static void htuser_show_task(int pid) sched_show_task(p); pr_err("UserList_KernelStack end\n"); } + put_task_struct(p); } static void htuser_list_insert(int pid, int count) @@ -242,7 +248,7 @@ ssize_t htuser_list_store(struct kobject *kobj, len = p ? (size_t)(p - buf) : count; strncpy(tmp, buf, len); - if (strncmp(tmp, "on", CMD_MIN_LEN) == 0) { + if (strncmp(tmp, "on,", CMD_MIN_LEN) == 0) { if (htuser_list_store_on(tmp, len, pid)) return -EINVAL; } else if (unlikely(strncmp(tmp, "off", CMD_MIN_LEN) == 0)) { -- Gitee