From nobody Sun Feb 8 06:55:34 2026 Received: from mail-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 345522FFDCB for ; Sun, 26 Oct 2025 20:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761510119; cv=none; b=PJ0yQle9wayPb4RM6VWWsFS41gvwEv8ufyZwF1WHqZay+wfxKpypT2ZoNWjUsVedjB7Xx4yGK4qt84CHhLfTx0n7Ilx9ieLeY6q9BIgHi63m8Ak86fdrwmjS65mL2fqHUUphm/rm0WWrXjPs0vtfZj6RW3+4I59B+RVrHD1VedI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761510119; c=relaxed/simple; bh=N3mn3jtqr7f8HNG2DIDfaOlSX3NGho6+CId/b6FYS8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WluNzcB1wJYzTLXy+VgDiq9elIEXnI9U1O9TQKLIzv7KSfPdssp2dc19ZSdcqwaHE54t+whll/TbC4KS1qF/HKNasJ7sBFfJCcSZdF5FjkYsKIsBiz+OtvSaIg6nG1Qu2luhVL9vq3UQzxhBeA/QSznzn13l7PemYXVPU+6DQjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Z4Xg86vv; arc=none smtp.client-ip=209.85.166.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z4Xg86vv" Received: by mail-il1-f182.google.com with SMTP id e9e14a558f8ab-430ab5ee3afso40403855ab.2 for ; Sun, 26 Oct 2025 13:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761510117; x=1762114917; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kMS3PI8XML9mSaAJp4Ws8nz4ou7XIeiRLoOGzBW6NzE=; b=Z4Xg86vvvDzfe3vEbk01TsrTd3ATHVxVjSJS1r3QilfZLlW/papHA1M6J40T2rMy5j V9Js2vaXTep+lHyIqD0M2Vmr+fwgaPwc2U1TJsliScrZx5X4sUcf6XBM9FwaQpe7dPn2 NvhiAZLG7lD/VRpOCuNXUj4pkTP58KbVR0qKnhgQX2SKVZ3QUdJE6EAEqzvgIhAVRhke JkNmRqrBjwGKstw+MHFzBmkQoesLsxfZyd+aUOCDZCe7Vdz19beJm3T6Xkh9fWpoDjCR 62g0Fn3Ki1wwjvcw5MRDt0bi4zSzZqMqNgNR972VveKku8Uou6ZUNlz6KDXFYCg1N6DH K1CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761510117; x=1762114917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kMS3PI8XML9mSaAJp4Ws8nz4ou7XIeiRLoOGzBW6NzE=; b=Oohir7nOAq5B85oqbuphf78JUxX/mJonqN09GXB6ByDxwjyXTK6lNuPPH6ywL/B2Aj +kK94icOXIqa/rr72Qm8+AMcKEERF/uylJliLbOu+BSsEsN4eJc06hDUL1Zyy/37vQjK giUuLRrLOqBqlzjd5mEMrgouGJAGbMCTJ2upf9e3OOpMyuaJTWvKoN09X6jhV45PKGdh 35lZuuBHKd6X0VJaxCivVJPwVuTvsGc2ay6QsXKzLEJkYNuWZRKdOG/k2wd68uak6c1S p3B3gVcO5yQzLONTZkOVm42DXk0SBBvHER2C9Tt/DC2PddV/kKS4FXqC0rGCB599oAfF pYwA== X-Gm-Message-State: AOJu0Yze10wP/Ztb+qF5HKjQ7XfAD6Lcag6epy5l4IAn2x0YyNJ91rEx kYmVKdSG7OEn/KAjFQTU3Zbk0cWpnbmTs/6C5EP8d0X5f2/N+7sZjQvqgChjmQ== X-Gm-Gg: ASbGncsx/PwY6Y1O/z02iOaYQ5J7Ps5h6/dSc4wRsjqSQwoe/IhUsIJJ7t1YGYJMul2 KEt8/hvLkOc25zwjMMJFYtbRWXsi7oLE+C57KLf4QBf0+kJKUycnjFibwEUx2YUlL+T6vTXvGls gk4u9lJ2uDnlOeFxKwAQvcgu+jj+6ckrrAWQXxkullzCXUcGIGdYeFI0ufgaXvcCLUrXR/HGR3F slT6yrvc+C1qsvGMAMiidsIzRYkPhMdhACmSQFLcOijMjlyu1SDVWLn8t8osOcopR120fwPAkG9 fuQo/rH2LKsqLBhD+WvOnIADIG4Kg3kHG0fgrzz/dwlkVeH4pdcu6ZFmOkrVVSqrgdKkWCNwUyw Y/86zDI/Za+p3I0Y+VzVnQOabgVOIeCC7A7ALRzhjJDUxWoGaErtskm9J6zQhRky0/kpIy74sGI OqH8N2zXhjCfy/eWwWwD7d4Y6k6ZN6XJANSdsf5g0EwtFbDJ0UTgWoZkkR0Ju4hOsUSmU= X-Google-Smtp-Source: AGHT+IHoD/E6/7S4XtlsDVYIgNQ2fcmlLSJ+sViycIXbntq167DJGyVxGCHUMpBxeARcNlYgNcasbQ== X-Received: by 2002:a05:6e02:2488:b0:42f:8d40:6c4b with SMTP id e9e14a558f8ab-431ebee1b8fmr126908725ab.11.1761510116921; Sun, 26 Oct 2025 13:21:56 -0700 (PDT) Received: from godzilla.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 8926c6da1cb9f-5aea995e766sm2278412173.51.2025.10.26.13.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Oct 2025 13:21:56 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org Cc: akpm@linuxfoundation.org, Jim Cromie , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn Subject: [PATCH v2 1/2] checkpatch: add --debug rx=1|foo option and drx_print() helper Date: Sun, 26 Oct 2025 14:21:40 -0600 Message-ID: <20251026202142.1622060-2-jim.cromie@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251026202142.1622060-1-jim.cromie@gmail.com> References: <20251026202142.1622060-1-jim.cromie@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" checkpatch has ~235 heuristic s/$patt// statements which strip code-snippets that are "OK", leaving the remainder for further heuristics to apply further "cleanups". Many of these have obvious purpose, but surely some are inscrutable. To help with maintenance of those harder "cleanup" cases, add a helper fn: drx_print($reason), which is designed to be called from a s/// or s///g statement (in the 'replacement' side), to "explain" itself. You can use it to instrument the code to show its work, then validate that explanation by experiment and exersize: s/$patt/drx_print("why")/e; # maintainer's best guess s/$patt/drx_print("whys")/ge; # note the 'e' modifier To activate drx_print() output, pass "--debug rx=3D1" to enable all the instrumented cleanup heuristics. For more selectivity (in case usage grows), pass: "--debug rx=3Dfoo" to select "foo" cleanups. Here it is in action, on a patch which triggered enough noise that I wanted this visibility into what it was doing. $ scripts/checkpatch.pl --strict --debug rx=3Dinspect ../linux.git/pt-1 drx_print: -arg-inspections- >> Matched (`$&`): <__builtin_constant_p(cls> >> Capture 1 (`$1`): <__builtin_constant_p> Also validate --debug KEYs for clear error: $ scripts/checkpatch.pl --strict ../linux.git/pt-1 --debug foo=3D1 Unknown debug key 'foo', expecting: 'values possible type attr rx' Signed-off-by: Jim Cromie --- v2 - extend --debug key=3D1 rather than add new option --- scripts/checkpatch.pl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e722dd6fa8ef..c174e3bef2b2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -169,6 +169,34 @@ my $DO_WHILE_0_ADVICE =3D q{ Enjoy this qualification while we work to improve our heuristics. }; =20 +my $dbg_rx =3D 0; +# call this from s/$patt/drx_print("why")/e - to see whats happening there. +sub drx_print { + my ($reason) =3D @_; + return "" unless $dbg_rx; + + if ($dbg_rx ne '1') { + # $dbg_rx is seeking "reason" + # search w/o using regex, to preserve caller s///e context. + return "" if ($dbg_rx and index($reason, $dbg_rx) =3D=3D -1); + } + + # report what was matched and removed (in caller) + print "drx_print: $reason\n"; + print " >> Matched (`\$&`): <$&>\n"; + + # Only print captures if they exist + if (defined $1) { + print " >> Capture 1 (`\$1`): <$1>\n"; + } + if (defined $2) { + print " >> Capture 2 (`\$2`): <$2>\n"; + } + # The subroutine must return the replacement string. For s/$pat// + # statements (our target use), this is an empty string. + return ""; +} + sub uniq { my %seen; return grep { !$seen{$_}++ } @_; @@ -451,7 +479,13 @@ my $dbg_values =3D 0; my $dbg_possible =3D 0; my $dbg_type =3D 0; my $dbg_attr =3D 0; + +my @known_keys =3D qw(values possible type attr rx); +my %known_keys; +$known_keys{$_}++ for @known_keys; + for my $key (keys %debug) { + die "Unknown debug key '$key', expecting: '@known_keys'\n" unless $known_= keys{$key}; ## no critic eval "\${dbg_$key} =3D '$debug{$key}';"; die "$@" if ($@); --=20 2.51.0 From nobody Sun Feb 8 06:55:34 2026 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) (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 43ED02FFDD8 for ; Sun, 26 Oct 2025 20:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761510121; cv=none; b=tB/z7A59WjazXy1tic82wp8q8UgnDHArhWc+ZcdF65ZYWUTtwdUZ6Agjfto++ip4aD/Xc3Wg7iEH5umsaWy5DkfqeKO6KjlyPDSUGGIWvH3jpw9U8bun3jMrQKk2L3rK6Ce+cRuweOSkGSVNDtG0cBqGhhAquoTy/XyEkSmwtks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761510121; c=relaxed/simple; bh=e3VGKCjUxHn7nzzSTsB0ej6NckM4M6wwFuneBTXLdyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WMhMXLRGSyuR2fOk7V6KxWdqGZSAhGE4cR02nlXYwbWVoMfW43TG2BppMBS0PS0wxW8DypGTQSchcw3QX7FEsAVFxk1D6KcFTLbHzrp2Ei3/GHZAKiAV59avejmjbpCOkn3Lgp9tHBUh0WJDZVCnrxdrbWuwXplc12Q5HJKcWgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dw0uP2WT; arc=none smtp.client-ip=209.85.166.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dw0uP2WT" Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-431da4fa224so40250915ab.2 for ; Sun, 26 Oct 2025 13:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761510118; x=1762114918; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nh8UGtr25ZVdzNwUOEe9kMcrpoR9dn5kWpAcgb68LcI=; b=Dw0uP2WTD3jKgtyAfpeKl6gUlZqaiA/BJ/Crq47mqA1N83U6DINSfPcQTQzm7kII2V xwaxAqi3My+Bdf6FWe5mDB0qidN9q12Lx/eMoprNXcc8AqM05xnrc1ksUUIh2KDPi3XS XSg/+uotEo/6eYr+iZzmyGMwJXE/ojDKFiQ/0sXmEVajK1m1SzDTIZZ3OC6Vb7LJgIhR rildczJ7ZU1t4dkl4Wjgym1/Y1InvBvq0yreepGPF/LtXDxz6weQuT7G8OD4MfNUoPff xqInKICKPt3g7mQM10UVZ1yVQ5Zz3M2vuYnqXc9RpGx0Yzi6KGbwmTOeg0/weyROPi8r WY4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761510118; x=1762114918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nh8UGtr25ZVdzNwUOEe9kMcrpoR9dn5kWpAcgb68LcI=; b=W+0d/Wgtt2nsdZieIeodFl926SBJHa7atcH8sdAobL7GZ4h6qY+7y3ssRJdMhJ6aBr lQ42F2ppDpwpKg4jAZmEfHjXeSnvKkd3VwVpO9HW88BCMtpBc5i0j6/s93gWhvB1R+HD tIYsYxK09H7CJvTS/pRqroySLLCzd+zwMPECHPcGH76Dwv4x4XGFzCgkzfzUr4c8aOHm kT0p/qSSO6Ehf/IkdEh/M+0j/YdDxpszA1L1MKwv362gbL+QZdT5LdsHUSdWDY2nApNG x+nUhzF2pVXxh0F9Uwry9i9DcrzTGCfTgiyawtXMjMsGJQS96heemSLNYR75q1BCuLTW kgBw== X-Gm-Message-State: AOJu0YyUHlt5Cy4NC/4zMhx6UaIz938vYfgXfgbpUkcsuJ4swzMu6OhH A+rEdUG0+v5hL5D5rn2INw0x8WWpwuieXfk9/rFYcXPb+/3OSWbxLaKBlrrvaw== X-Gm-Gg: ASbGncvTo70vUHF7bvXd+PTXuB5+PimbnGHsCt6Az2IgTjg/j7U6je6K45O43JhQ6LR XOWH/daP7/lsNhcpYcUXNFjTjD397UYH7xJ9JnnEPuxYpKwZf++xwN3UvmoTRy8wj2WD05O97ZY g/lzxqS86NWsHo9GspNG8QKCNiHxjI1tXZ44NnhBrAAF59R53lfN3Ps4WWOMwzeu80EdsGtNwck 2TgAc8OkokCuUrOrpnBrMAVdcB4h1lelvpX+nQIXo4iU3RwZdsCBiwLggV/lxD7+LQPmlhaN+m5 abfnf9pqOa2fml915CJ8wyQkm5P9rx7pxvzlG5pLp6lnVr7y/51CCq0fztxcDCp8wZu7cG/fTdO TAY06JcTUEkAuNTFDSk0usKvZlVJay/u17U1c2rYVs3z5tUMzzkg8pR8/FThkWTmNEku9jEG2/4 YZwE5MhgTejAsX1lH5c8q0CxYTnT2ZU2KJg5J0MvGCcVVSEsyqMAH5BJGo X-Google-Smtp-Source: AGHT+IGX+d6dExac3obZdDxdgt08jybd+8vy337PdLfb/WjCbOR6uhXViML4/bPAIKNbW5oDHxiaRA== X-Received: by 2002:a05:6e02:300a:b0:431:d864:364c with SMTP id e9e14a558f8ab-431d86438femr195317155ab.17.1761510118154; Sun, 26 Oct 2025 13:21:58 -0700 (PDT) Received: from godzilla.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 8926c6da1cb9f-5aea995e766sm2278412173.51.2025.10.26.13.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Oct 2025 13:21:57 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org Cc: akpm@linuxfoundation.org, Jim Cromie , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn Subject: [PATCH v2 2/2] checkpatch: 3 use-cases for --debug rx=1 option Date: Sun, 26 Oct 2025 14:21:41 -0600 Message-ID: <20251026202142.1622060-3-jim.cromie@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251026202142.1622060-1-jim.cromie@gmail.com> References: <20251026202142.1622060-1-jim.cromie@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the drx_print() helper in 3 cases inside code which counts macro arg expansions. $ scripts/checkpatch.pl --strict patch-1 --debug rx=3D'##' drx_print: 'arg ##' catenations >> Matched (`$&`): <_id##> drx_print: 'arg ##' catenations >> Matched (`$&`): <_id##> drx_print: '#|## arg' catenations >> Matched (`$&`): <##_model> drx_print: '#|## arg' catenations >> Matched (`$&`): <##_model> $ scripts/checkpatch.pl --strict patch-1 --debug rx=3D'insp' drx_print: -arg-inspections- >> Matched (`$&`): <__builtin_constant_p(cls> >> Capture 1 (`$1`): <__builtin_constant_p> NB: see also the extended --debug key=3D1 facility: $ scripts/checkpatch.pl --strict ../linux.git/pt-1 --debug foo=3D1 Unknown debug key 'foo', expecting: 'values possible type attr rx' NB: I moved the 2 #|## strippers above the more complex macro, because the latter caught one ## case that it needn't have. Signed-off-by: Jim Cromie --- scripts/checkpatch.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c174e3bef2b2..240ddab17d89 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6078,9 +6078,17 @@ sub process { next if ($arg =3D~ /\.\.\./); next if ($arg =3D~ /^type$/i); my $tmp_stmt =3D $define_stmt; - $tmp_stmt =3D~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__str= ingify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*= \s*$arg\s*\)*\b//g; - $tmp_stmt =3D~ s/\#+\s*$arg\b//g; - $tmp_stmt =3D~ s/\b$arg\s*\#\#//g; + + $tmp_stmt =3D~ s/\#+\s*$arg\b/drx_print("'#|## arg' catenations")/ge; + $tmp_stmt =3D~ s/\b$arg\s*\#\#/drx_print("'arg ##' catenations");/ge; + $tmp_stmt =3D~ s{ + \b(__must_be_array|offsetof|sizeof|sizeof_field| + __stringify|typeof|__typeof__|__builtin\w+| + typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b } + { + drx_print("-arg-inspections-"); + }xge; + my $use_cnt =3D () =3D $tmp_stmt =3D~ /\b$arg\b/g; if ($use_cnt > 1) { CHK("MACRO_ARG_REUSE", --=20 2.51.0