Skip to content

Commit 344b847

Browse files
committed
task_work: Introduce task_work_cancel() again
JIRA: https://issues.redhat.com/browse/RHEL-55603 upstream ======== commit f409530 Author: Frederic Weisbecker <frederic@kernel.org> Date: Fri Jun 21 11:15:59 2024 +0200 description =========== Re-introduce task_work_cancel(), this time to cancel an actual callback and not *any* callback pointing to a given function. This is going to be needed for perf events event freeing. Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240621091601.18227-3-frederic@kernel.org Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent 28abeba commit 344b847

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/linux/task_work.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int task_work_add(struct task_struct *task, struct callback_head *twork,
3131
struct callback_head *task_work_cancel_match(struct task_struct *task,
3232
bool (*match)(struct callback_head *, void *data), void *data);
3333
struct callback_head *task_work_cancel_func(struct task_struct *, task_work_func_t);
34+
bool task_work_cancel(struct task_struct *task, struct callback_head *cb);
3435
void task_work_run(void);
3536

3637
static inline void exit_task_work(struct task_struct *task)

kernel/task_work.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ task_work_cancel_func(struct task_struct *task, task_work_func_t func)
133133
return task_work_cancel_match(task, task_work_func_match, func);
134134
}
135135

136+
static bool task_work_match(struct callback_head *cb, void *data)
137+
{
138+
return cb == data;
139+
}
140+
141+
/**
142+
* task_work_cancel - cancel a pending work added by task_work_add()
143+
* @task: the task which should execute the work
144+
* @cb: the callback to remove if queued
145+
*
146+
* Remove a callback from a task's queue if queued.
147+
*
148+
* RETURNS:
149+
* True if the callback was queued and got cancelled, false otherwise.
150+
*/
151+
bool task_work_cancel(struct task_struct *task, struct callback_head *cb)
152+
{
153+
struct callback_head *ret;
154+
155+
ret = task_work_cancel_match(task, task_work_match, cb);
156+
157+
return ret == cb;
158+
}
159+
136160
/**
137161
* task_work_run - execute the works added by task_work_add()
138162
*

0 commit comments

Comments
 (0)