From nobody Sat Feb 7 11:38:19 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7AE6C001DB for ; Tue, 8 Aug 2023 15:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbjHHPhv (ORCPT ); Tue, 8 Aug 2023 11:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbjHHPg4 (ORCPT ); Tue, 8 Aug 2023 11:36:56 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C3D02113 for ; Mon, 7 Aug 2023 20:30:27 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-76c845dc5beso312577785a.1 for ; Mon, 07 Aug 2023 20:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691465426; x=1692070226; 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=Qq8u+P5B599QNMU/hMo97WZZje4v2kxUMmhAQURJTHU=; b=lrC69s/9+ztDiIY1TLG6g1c6x7Nx2jLCtsJtQTTX7FNKTGGAl7mvxs2oCQVyBQocCA N3AxMNtBHlyn0Un41DO29tDJibRHSUk6rjR7G19/9mJpTYsI06Kw7zjjzyOoAD6Z4GCm +KTlhbUw+6Lt2Jsp9fUOuxugb5wHQjsVj8JkduXP9wiY0qO3AfGcuoP8VawFResSaCti 0enkDVNEKcgkx4uY3A55Z4zMTngcYayl2eHWhyGajNcftM/fNLUJOqrkqs3ef8yr/Uvz IdAibuiXBwxVYeUXxYN1q+keEWqE0X7yZ3LQTSEzhMD7jR1U3a6XDh7uTvJAfqUd3XqK 587w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691465426; x=1692070226; 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=Qq8u+P5B599QNMU/hMo97WZZje4v2kxUMmhAQURJTHU=; b=E4FWwoy0DVgvRgYPc8/312skrRyXfzyJyuIcTDOZU+3woo/lFUQ7zG8Ozfi8zMorNC AAmnnPes5SBpfJFWMcUSV1Q3qlEepAKYWL6JyxBmM3oapHqVGmJSdFU04DFU4LJ7el12 poDTo7wOU9VjTIbH3xhz5pdvxNwL/B1dp+cWCwItw0dlZRJjkKKrlf4RAo48g4lw0mSq OjNHj+B/J1IpqEE45nMr4IEWoPm+oiaReiuGvGSUaf5wWjod86KTn/h0tH6CKgkijzpu 1mn6WhARYlFiPbsJ0FF+aicTZtNoeYro4S8hb+VyX3Dr37Di2ywnVTkKMOoYAbaeYlYT +OYQ== X-Gm-Message-State: AOJu0YyzebIAXH7WW8ErozFTmuPRlwElLOs82kh0G8DZJfBM2i99pfkR 9Mk909V8tJrmHgMqZj8NHEFxaXafVeypXQ== X-Google-Smtp-Source: AGHT+IHQMqiYicHT+fmzZnAJg4yOkeV3vYlkkuP2ZRNmw/k13b7oxxofxm0xMcjjDbLn7f/9UnJtfQ== X-Received: by 2002:a05:620a:258a:b0:765:3ca0:3708 with SMTP id x10-20020a05620a258a00b007653ca03708mr8876142qko.75.1691465425812; Mon, 07 Aug 2023 20:30:25 -0700 (PDT) Received: from frodo.. (c-73-78-62-130.hsd1.co.comcast.net. [73.78.62.130]) by smtp.googlemail.com with ESMTPSA id em12-20020a0566384dac00b0042bb5a8e074sm2854031jab.8.2023.08.07.20.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 20:30:25 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, Jim Cromie , apw@canonical.com, joe@perches.com Subject: [PATCH 1/2] checkpatch: special case extern struct in .c Date: Mon, 7 Aug 2023 21:30:18 -0600 Message-ID: <20230808033019.21911-2-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230808033019.21911-1-jim.cromie@gmail.com> References: <20230808033019.21911-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" "externs should be avoided in .c files" needs an exception for linker symbols, like those that mark the start, stop of many kernel sections. Since checkpatch already checks REALNAME to avoid looking at fragments changing vmlinux.lds.h, add a new else-if block to look at them instead. As a simple heuristic, treat all words (in the patch-line) as possible symbols, to screen later warnings. For my test case, the possible-symbols included BOUNDED_BY (a macro), which is extra, but not troublesome - these are just to screen WARNINGS that might be issued on later fragments (changing .c files) Where the WARN is issued, precede it with an else-if block to catch one common extern-in-c use case: "extern struct foo bar[]". Here we can at least issue a softer warning, after checking for a match with a maybe-linker-symbol parsed earlier from the patch. Though heuristic, it worked for my test-case, allowing both start__, stop__ $symbol's (wo the prefixes specifically named). I've coded it narrowly, it can be expanded later to cover any other expressions. It does require that the externs in .c's have the additions to vmlinux.lds.h in the same patch. And requires vmlinux.lds.h before .c fragments. Cc: apw@canonical.com Cc: joe@perches.com Signed-off-by: Jim Cromie --- scripts/checkpatch.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 880fde13d9b8..6aabcc1f66c1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -74,6 +74,8 @@ my $git_command =3D'export LANGUAGE=3Den_US.UTF-8; git'; my $tabsize =3D 8; my ${CONFIG_} =3D "CONFIG_"; =20 +my %maybe_linker_symbol; # for externs in c exceptions, when seen in *vmli= nux.lds.h + sub help { my ($exitcode) =3D @_; =20 @@ -6051,6 +6053,9 @@ sub process { =20 # check for line continuations outside of #defines, preprocessor #, and asm =20 + } elsif ($realfile =3D~ m@/vmlinux.lds.h$@) { + $line =3D~ s/(\w+)/$maybe_linker_symbol{$1}++/ge; + #print "REAL: $realfile\nln: $line\nkeys:", sort keys %maybe_linker_= symbol; } else { if ($prevline !~ /^..*\\$/ && $line !~ /^\+\s*\#.*\\$/ && # preprocessor @@ -7119,6 +7124,21 @@ sub process { "arguments for function declarations should follow identifier\n" = . $herecurr); } =20 + } elsif ($realfile =3D~ /\.c$/ && defined $stat && + $stat =3D~ /^\+extern struct\s+(\w+)\s+(\w+)\[\];/) + { + my ($st_type, $st_name) =3D ($1, $2); + + for my $s (keys %maybe_linker_symbol) { + #print "Linker symbol? $st_name : $s\n"; + goto LIKELY_LINKER_SYMBOL + if $st_name =3D~ /$s/; + } + WARN("AVOID_EXTERNS", + "found a file-scoped extern type:$st_type name:$st_name in .c file= \n" + . "is this a linker symbol ?\n" . $herecurr); + LIKELY_LINKER_SYMBOL: + } elsif ($realfile =3D~ /\.c$/ && defined $stat && $stat =3D~ /^.\s*extern\s+/) { --=20 2.41.0 From nobody Sat Feb 7 11:38:19 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16535C41513 for ; Tue, 8 Aug 2023 15:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbjHHPhx (ORCPT ); Tue, 8 Aug 2023 11:37:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjHHPg4 (ORCPT ); Tue, 8 Aug 2023 11:36:56 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7362115 for ; Mon, 7 Aug 2023 20:30:28 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-403e7472b28so34614861cf.2 for ; Mon, 07 Aug 2023 20:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691465427; x=1692070227; 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=5pwtHw5vOD1RYKMIWegCIn/ujHRoRt+MzmoTcrvlAMU=; b=qKRFBwr8PO8Pvp07hvRp77Hhv7IVQwVDuZiGG5YmZpjkQD5Eyr8mgyRFnMQ7fdmbhZ 6fCo6ml9GTzmtSBGnV0U2jYlL/hVQ0/4QoZh7sMzdVALsSliilDqnpJDSDx5vccXPJnD 1os+/cy0e+Aa3quHrUGzVmKlyKAZws8JiS16wsqHAUHyU2tvskmUSDZ6h2bkQBYzHp4y Y4n6JQokCcYfm+m7+opszjr/oXqrax80Ap2ki64Y4dzPqzhAT3bM6n0ScWr+eDR7bY/X 4DCrfzcOPzh7aRQy3QhSuDSGsFxfNNe8UcNtqYfAbS/gkgm1lqrCqc/4bvBZV435VY8F mX8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691465427; x=1692070227; 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=5pwtHw5vOD1RYKMIWegCIn/ujHRoRt+MzmoTcrvlAMU=; b=Tfjz8lNBg4NOceU6SO1U1HMLxOa4TDQlvUQkUR5eTfA/Y59WfX2cJgx2PvWDk1d/D8 zZrpHpl5KP/sfokks2bn8cHDEBvYarVR7q/XKZC+nmRhtxh8ey2BzMm7tM7HtRo5BN/i SEsVqntsaV+mmnovwWduarFmYP1wDengyJtyx6F+NF6l3CMuX1EGZ0aTbKmXxopnKe9M pKJBjS+HVt0Bb/Ttb7R1yaoXsIgeT9nZwXbunO8X3906lX7oiRgEEsgGG/36hFzyA1ef YHRd+2OScIFwtH+ETzyzrLT5ZxEeLjAOWACtjZgiDCtLbjimobtKUU2G8rOMl9k7gNX/ HIsw== X-Gm-Message-State: AOJu0YxaImb4ozwgsewYnLZZCCeG8NZtYeOfdxREaW8cQGDHYl1WNOBH VPuXzQrScZtfbkk60TfiwQShNsxjBEU2TA== X-Google-Smtp-Source: AGHT+IFTlNsk+I0QB9zoXtMVAjjI96pH73V9i1H2ISxoofH/hrPBkuGZTscXhj2wtJbTBeRj4WKuTw== X-Received: by 2002:a05:622a:14c8:b0:403:b645:86fa with SMTP id u8-20020a05622a14c800b00403b64586famr15664525qtx.24.1691465426827; Mon, 07 Aug 2023 20:30:26 -0700 (PDT) Received: from frodo.. (c-73-78-62-130.hsd1.co.comcast.net. [73.78.62.130]) by smtp.googlemail.com with ESMTPSA id em12-20020a0566384dac00b0042bb5a8e074sm2854031jab.8.2023.08.07.20.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 20:30:26 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, Jim Cromie , apw@canonical.com, joe@perches.com Subject: [PATCH 2/2] checkpatch: reword long-line warning about commit-msg Date: Mon, 7 Aug 2023 21:30:19 -0600 Message-ID: <20230808033019.21911-3-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230808033019.21911-1-jim.cromie@gmail.com> References: <20230808033019.21911-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Reword the warning to complain about line length 1st, since thats whats actually tested. Cc: apw@canonical.com Cc: joe@perches.com Signed-off-by: Jim Cromie --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 6aabcc1f66c1..6e789dc07420 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3272,7 +3272,7 @@ sub process { # A Fixes:, link or signature tag line $commit_log_possible_stack_dump)) { WARN("COMMIT_LOG_LONG_LINE", - "Possible unwrapped commit description (prefer a maximum 75 chars = per line)\n" . $herecurr); + "Prefer a maximum 75 chars per line (possible unwrapped commit des= cription?)\n" . $herecurr); $commit_log_long_line =3D 1; } =20 --=20 2.41.0