lkml.org 
[lkml]   [2021]   [Jul]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] task_work: return -EBUSY when adding same work
Date
when same work is added to task->task_works list one by one,
the list becomes endless loop. So return -EBUSY when this
situation happen.

Signed-off-by: yaozhenguo <yaozhenguo1@gmail.com>
---
kernel/task_work.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 1698fbe..5061ebf 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -27,7 +27,7 @@
* list is LIFO.
*
* RETURNS:
- * 0 if succeeds or -ESRCH.
+ * 0 if succeeds or -ESRCH, -EBUSY.
*/
int task_work_add(struct task_struct *task, struct callback_head *work,
enum task_work_notify_mode notify)
@@ -41,6 +41,8 @@ int task_work_add(struct task_struct *task, struct callback_head *work,
head = READ_ONCE(task->task_works);
if (unlikely(head == &work_exited))
return -ESRCH;
+ if (unlikely(head == work))
+ return -EBUSY;
work->next = head;
} while (cmpxchg(&task->task_works, head, work) != head);

--
1.8.3.1
\
 
 \ /
  Last update: 2021-07-09 14:29    [W:0.049 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site