Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kthread_worker: check all delayed works when destroy kthread worker

When destroying a kthread worker warn if there are still some pending
delayed works. This indicates that the caller should clear all pending
delayed works before destroying the kthread worker.

Link: https://lkml.kernel.org/r/20230104144230.938521-1-qiang1.zhang@intel.com
Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Zqiang and committed by
Andrew Morton
eb79fa7e dd106111

+5
+5
kernel/kthread.c
··· 1382 1382 * Flush and destroy @worker. The simple flush is enough because the kthread 1383 1383 * worker API is used only in trivial scenarios. There are no multi-step state 1384 1384 * machines needed. 1385 + * 1386 + * Note that this function is not responsible for handling delayed work, so 1387 + * caller should be responsible for queuing or canceling all delayed work items 1388 + * before invoke this function. 1385 1389 */ 1386 1390 void kthread_destroy_worker(struct kthread_worker *worker) 1387 1391 { ··· 1397 1393 1398 1394 kthread_flush_worker(worker); 1399 1395 kthread_stop(task); 1396 + WARN_ON(!list_empty(&worker->delayed_work_list)); 1400 1397 WARN_ON(!list_empty(&worker->work_list)); 1401 1398 kfree(worker); 1402 1399 }