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

From: Joe Perches
Date: Sun Apr 24 2022 - 19:45:50 EST


On Mon, 2022-04-25 at 08:31 +0900, Tetsuo Handa wrote:
> 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.
[]
> diff --git 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\b\s*\(/ || $line =~ /\bflush_workqueue\b\s*\(\s*\bsystem_wq\b\s*\)/ ||
> + $line =~ /\bflush_workqueue\b\s*\(\s*\bsystem_(highpri|long|unbound|freezable|power_efficient|freezable_power_efficient)_wq\b\s*\)/) {

Several of the uses of \b are not necessary.

And it's probably more readable using separate lines and it looks as
if the 3rd test is unnecessary as it could be combined with the 2nd.

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);