mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users
@ 2026-06-05  7:43 Marco Crivellari
  2026-06-06  1:22 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Crivellari @ 2026-06-05  7:43 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
	Tejun Heo, Frederic Weisbecker, Sebastian Andrzej Siewior,
	Marco Crivellari, Michal Hocko, Breno Leitao

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@suse.com>
---
Changes in v3:
- code aligned to open parens

- ERROR changed with WARN

Link to v2: https://lore.kernel.org/all/20260604154447.381477-1-marco.crivellari@suse.com/

Changes in v2:
- removed $line from the test (Joe Perches)

- devm_alloc_workqueue() regex take into account also (Joe Perches)

- defined() on variables and other improvements (Joe Perches)

Link to v1: https://lore.kernel.org/all/20260603140941.320063-1-marco.crivellari@suse.com/

 scripts/checkpatch.pl | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0492d6afc9a1..f1b03897b6e7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7804,8 +7804,31 @@ sub process {
 			ERROR("UNINITIALIZED_PTR_WITH_FREE",
 			      "pointer '$1' with __free attribute should be initialized\n" . $herecurr);
 		}
-	}
 
+# check alloc_workqueue() parameters for WQ_PERCPU and WQ_UNBOUND uses
+		if (defined($stat) &&
+			$stat =~ /^[ \+]\s*(?:$Lval\s*=\s*)?((?:devm_)?alloc_workqueue)\s*($balanced_parens)/) {
+
+			my $func = $1;
+			my $args = $2;
+			my $has_percpu = $args =~ /\bWQ_PERCPU\b/;
+			my $has_unbound = $args =~ /\bWQ_UNBOUND\b/;
+			my $error_msg;
+
+			if ($has_percpu && $has_unbound) {
+				$error_msg = "$func() should not contain both WQ_PERCPU and WQ_UNBOUND\n";
+			} elsif (!$has_percpu && !$has_unbound) {
+				$error_msg = "$func() must specify either WQ_PERCPU or WQ_UNBOUND\n";
+			}
+
+			if (defined($error_msg)) {
+				my $stmt_cnt = statement_rawlines($stat);
+				my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
+				WARN("ALLOC_WORKQUEUE_FLAGS",
+					 $error_msg . $herectx);
+			}
+		}
+	}
 	# If we have no input at all, then there is nothing to report on
 	# so just keep quiet.
 	if ($#rawlines == -1) {
-- 
2.54.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users
  2026-06-05  7:43 [PATCH v3] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users Marco Crivellari
@ 2026-06-06  1:22 ` Joe Perches
  2026-06-08  8:04   ` Marco Crivellari
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2026-06-06  1:22 UTC (permalink / raw)
  To: Marco Crivellari, linux-kernel
  Cc: Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn, Tejun Heo,
	Frederic Weisbecker, Sebastian Andrzej Siewior, Michal Hocko,
	Breno Leitao

On Fri, 2026-06-05 at 09:43 +0200, Marco Crivellari wrote:
> 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.
[]
> Signed-off-by: Marco Crivellari <[marco.crivellari@suse.com](mailto:marco.crivellari@suse.com)>
> ---
> Changes in v3:
> - code aligned to open parens

Not so.

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7804,8 +7804,31 @@ sub process {
>  			ERROR("UNINITIALIZED_PTR_WITH_FREE",
>  			      "pointer '$1' with __free attribute should be initialized\n" . $herecurr);
>  		}
> -	}
>  
> +# check alloc_workqueue() parameters for WQ_PERCPU and WQ_UNBOUND uses
> +		if (defined($stat) &&
> +			$stat =~ /^[ \+]\s*(?:$Lval\s*=\s*)?((?:devm_)?alloc_workqueue)\s*($balanced_parens)/) {

Properly aligned would be 2 tabs then 4 spaces

		    $stat =~ /^[ \+]\s*(?:$Lval\s*=\s*)?((?:devm_)?alloc_workqueue)\s*($balanced_parens)/) {
[]

> +			if (defined($error_msg)) {
> +				my $stmt_cnt = statement_rawlines($stat);
> +				my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
> +				WARN("ALLOC_WORKQUEUE_FLAGS",
> +					 $error_msg . $herectx);

4 tabs then 5 spaces

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users
  2026-06-06  1:22 ` Joe Perches
@ 2026-06-08  8:04   ` Marco Crivellari
  0 siblings, 0 replies; 3+ messages in thread
From: Marco Crivellari @ 2026-06-08  8:04 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-kernel, Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn,
	Tejun Heo, Frederic Weisbecker, Sebastian Andrzej Siewior,
	Michal Hocko, Breno Leitao

On Sat, Jun 6, 2026 at 3:22 AM Joe Perches <joe@perches.com> wrote:
>
> On Fri, 2026-06-05 at 09:43 +0200, Marco Crivellari wrote:
> > 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.
> []
> > Signed-off-by: Marco Crivellari <[marco.crivellari@suse.com](mailto:marco.crivellari@suse.com)>
> > ---
> > Changes in v3:
> > - code aligned to open parens
>
> Not so.

Aha, thanks, I will send a new version.

-- 

Marco Crivellari

SUSE Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-08  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-05  7:43 [PATCH v3] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users Marco Crivellari
2026-06-06  1:22 ` Joe Perches
2026-06-08  8:04   ` Marco Crivellari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®