[PATCH v2] checkpatch: warn about flushing system-wide workqueues

From: Tetsuo Handa
Date: Sun Apr 24 2022 - 20:28:27 EST


Flushing the system-wide WQ has possibility of deadlock, for the caller
waits for completion of all works in that WQ even if the caller cannot
wait for completion of one of works due to locking dependency. Since
it is difficult to catch such attempts using lockdep, try to catch also
using checkpatch.

Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
---
Changes in v2:
Simplify matching, suggested by Joe Perches <joe@xxxxxxxxxxx>

scripts/checkpatch.pl | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 577e02998701..88491cfcfd59 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7226,6 +7226,13 @@ sub process {
"Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr);
}

+# check for flushing system-wide workqueues
+ if ($line =~ /\bflush_scheduled_work\s*\(/ ||
+ $line =~ /\bflush_workqueue\s*\(\s*system(_\w*)?_wq\s*\)/) {
+ ERROR("DEPRECATED_API",
+ "Flushing system-wide workqueues is dangerous and will be forbidden - see https://lkml.kernel.org/r/49925af7-78a8-a3dd-bce6-cfc02e1a9236\@I-love.SAKURA.ne.jp\n"; . $herecurr);
+ }
+
# check for various structs that are normally const (ops, kgdb, device_tree)
# and avoid what seem like struct definitions 'struct foo {'
if (defined($const_structs) &&
--
2.34.1