[PATCH] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users

From: Marco Crivellari

Date: Wed Jun 03 2026 - 10:23:10 EST


The workqueue API introduced a new flag, WQ_PERCPU, that has to be used when
WQ_UNBOUND is not present. One of these flags must be present, but not
both of them.

To limit usage mistakes, emit an ERROR if one of the below condition is met:
- alloc_workqueue() is called without WQ_PERCPU nor WQ_UNBOUND
- alloc_workqueue() is called with both WQ_PERCPU and WQ_UNBOUND

Signed-off-by: Marco Crivellari <marco.crivellari@xxxxxxxx>
---
scripts/checkpatch.pl | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0492d6afc9a1..2706aba6dac0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7804,6 +7804,22 @@ sub process {
ERROR("UNINITIALIZED_PTR_WITH_FREE",
"pointer '$1' with __free attribute should be initialized\n" . $herecurr);
}
+
+# check alloc_workqueue() flags parameter (2nd argument) for WQ_PERCPU, WQ_UNBOUND presence
+ if ($line =~ /\balloc_workqueue\s*\(/ &&
+ $stat =~ /\balloc_workqueue\s*\(\s*[^,]+\s*,\s*([^,]+)/s) {
+ my $flags = $1;
+ my $has_percpu = $flags =~ /\bWQ_PERCPU\b/;
+ my $has_unbound = $flags =~ /\bWQ_UNBOUND\b/;
+
+ if ($has_percpu && $has_unbound) {
+ ERROR("ALLOC_WORKQUEUE_FLAGS",
+ "alloc_workqueue() second parameter should not contain both WQ_PERCPU and WQ_UNBOUND\n" . $herecurr);
+ } elsif (!$has_percpu && !$has_unbound) {
+ ERROR("ALLOC_WORKQUEUE_FLAGS",
+ "alloc_workqueue() second parameter should specify either WQ_PERCPU or WQ_UNBOUND\n" . $herecurr);
+ }
+ }
}

# If we have no input at all, then there is nothing to report on
--
2.54.0