From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BB313B42D0 for ; Mon, 8 Jun 2026 08:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907847; cv=none; b=ZFjw6jW/9d50RmD126pR+EIsgiiKpc+xAuGEVlP0lMLnxJhid1j2ufVpZI6KhFpS9dQaN8NEODTq0OszlJfod5HHn3l/CxZFKPh9rRw5toLo3ubql15kEbHHqZ8LVLEOE6pulTxR1ndxVjrb+P9WnBhcG3iv5YALJHkgul3pLxs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907847; c=relaxed/simple; bh=hcTjDp1EfxwQnw/urVyeKAwSIlTPLq6M/hY/l56QG40=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LNRKBcZEWYbVQSFw2ETHubu+pLH4Jspcuj+9zL9/lGyoRmfd4ZU/VyosXU0hYlWEg2qqjQpQoRaMtWfG7srqeuyM6pwmnkgSELQLSHxCE4g8byHoLRBejcZXqLx2N78CPGXrFxoD6ZmtjJZ9SN5RAyzjdwW0lOIgJBzDJ57xpC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=FObWZiel; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="FObWZiel" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-46019b190b6so3019452f8f.3 for ; Mon, 08 Jun 2026 01:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780907839; x=1781512639; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=M3739DgLjK6VsBON8yOK0vZvO6MMDc5Y4SHJPAiSgfs=; b=FObWZieleDrbpxcW3wJNzXr0QoZD+7g2P962jnzzgHl3r1orRPx8kUezARJ7kmSdP1 xK4R7gxYBKvneSp8YyQGcrcK5ZZGvf2khMYHcXspL237LppuWoj7+FWYzb5MHT6HJUwx CeXN9kr/Cu68mv50atzxN5h3ub6F9GzICCLTMsbEhhe2RQy8b961XwLnilac9pMRpqz9 UtlQPsVN4xhWgj7t1umTMp7WoNy3DH+ZP5ATrdzSQep3H4tj9TV+IuO+Olwi73JpdqQ7 InpAHTq3/VeT8CsCTctG00LdnXccjCle0IRBkfMP1e4YSuqWGLyqcbXFV/1CnMsLtLc5 3F0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907839; x=1781512639; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=M3739DgLjK6VsBON8yOK0vZvO6MMDc5Y4SHJPAiSgfs=; b=rAjTDJ7i323xbRLEiYz4nd0vpBY+OSZo34r08xPWbZc+AZ7elOVZsgh48i4XBjN4yA lcFsWcFtf2FHWy2AmnsxW/0j62Lu76tDve7QGooDo4q4sHQdAexKbnL6gNEWsLcWAcPT Yornqzbqhm0qps5qySRBg675dpTCJY2TSjysGMyRhr+6aRPtZdcERba22iCg2H4m2kxZ 1jSN3aHieT8yKayPkxsa7GMEdXwXlnp9iGTIAJZyas3IwsX9eXsVla9gVJ2lgLk56uE3 WLuaoUzfNcSPe9iOXTkhVGQvNLkkXHYWndIdxUIilF1dU1OenmIksMfO52XcL9zPho3S uAlQ== X-Gm-Message-State: AOJu0Yy3xU+3/3m69XfUL7mOG9mWL0SUGAZnoYO8YYiHdq/S07gt+qiI n7vjTQQ+AyfJmU+ksUyqqDsjbb1WFw1SY4lZXDtJDxdte/mOfeoQ0CIVdcdZxftHqHNzqqtRhRn T20P92Mg= X-Gm-Gg: Acq92OFE7gjBfcGMYqXKD9JIi05cb9EhFr53Inxv2ygQKkhDG85T+IM/AyzJRVhleJq ytso+8O32h8tlio+RYdNfkheNYVJJ5m/FEk1q/yZcnUOkjWTF19Y5FciXT/QJnaqXaPDOqiqOeE /egFlDNeEK0Fj6tm7PD6nnvHnFjt6XFgCDXZUoyVO9KhXE3Q3Y6/ls0A+czZRmeA7ZDoBby0uZW rT6RXGa/1WpRPQHAyJXDo6bzKSiguEQM2lpzImvGXKo1fkiX9OEevhJDcL5pqxwyrmiXkNoEJTU KqS0DWL49ROnl4sC2DrJc5I+nsdwsW8xAm5xB804bDZIOxKib49xMa/rTnZSZUlDJ2p/uzhtUEU FsZ2tFwubQrng5wwxLYkCG+bjL6nH3XLxmrbPRrtapw4g0+xrqNQY46fMJw4b7fS5xByVw7i4S/ VI1M3DxRAUlm3gjFInS/js5L9aNtoT9/YjRT/vzgywX3aOTqtg2AE0N3YGMw== X-Received: by 2002:a05:600c:4fc6:b0:490:b432:6f1e with SMTP id 5b1f17b1804b1-490c2614bf9mr237191195e9.33.1780907839463; Mon, 08 Jun 2026 01:37:19 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4602cda363bsm38394117f8f.31.2026.06.08.01.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:37:19 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Tejun Heo , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko , Breno Leitao Subject: [PATCH v4] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users Date: Mon, 8 Jun 2026 10:37:11 +0200 Message-ID: <20260608083711.76885-1-marco.crivellari@suse.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- Changes in v4: - properly align code Link to v3: https://lore.kernel.org/all/20260605074309.49270-1-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..52da2dc4f467 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