From: Charalampos Mitrodimas <charmitro@posteo.net>
To: Alban Kurti <kurti@invicto.ai>
Cc: Joe Perches <joe@perches.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mugel Ojeda <ojeda@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 RESEND 1/1] checkpatch: add warning for pr_* and dev_* macros without a trailing newline
Date: Fri, 07 Feb 2025 18:19:33 +0000 [thread overview]
Message-ID: <m25xllr51m.fsf@posteo.net> (raw)
In-Reply-To: <20250206120911.175884-1-kurti@invicto.ai> (Alban Kurti's message of "Thu, 06 Feb 2025 12:09:12 +0000 (UTC)")
Alban Kurti <kurti@invicto.ai> writes:
> Add a new check in scripts/checkpatch.pl to detect usage of pr_(level)
> and dev_(level) macros (for both C and Rust) when the string literal
> does not end with '\n'. Missing trailing newlines can lead to incomplete
> log lines that do not appear properly in dmesg or in console output.
> To show an example of this working after applying the patch we can run
> the script on the commit that likely motivated this need/issue:
> ./scripts/checkpatch.pl --strict -g f431c5c581fa176f608ba3fdebb3c1051bad5774
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1140
> Signed-off-by: Alban Kurti <kurti@invicto.ai>
> ---
> Changelog since v1:
> - Strip comments before matching to avoid false positives.
> - Refactored the macro patterns for clarity.
>
> scripts/checkpatch.pl | 46 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 9eed3683ad76..3256b5f31835 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3888,6 +3888,52 @@ sub process {
> }
> }
>
> +# check for pr_* and dev_* logs without a newline for C and Rust files to avoid missing log messages
> + my $log_macro_pattern = qr{
> + \b
> + (
> + pr_(?:emerg|alert|crit|err|warn|notice|info|debug)
> + | dev_(?:emerg|alert|crit|err|warn|notice|info|dbg)
> + )
> + (!?)
> + \s*
> + \(
> + \s*
> + "([^"]*)"
> + }x;
> +
> + if ($realfile =~ /\.(?:c|h|rs)$/) {
> + if ($rawline =~ /^\+/) {
> + my $cleanline = $rawline;
> +
> + $cleanline =~ s/^[+\s]+//;
> + $cleanline =~ s/\r?$//;
> +
> + $cleanline =~ s{/\*.*?\*/}{}g;
> + $cleanline =~ s{//.*}{}g;
> +
> + if ($cleanline =~ /$log_macro_pattern/) {
> + my $macro_call = $1;
> + my $maybe_excl = $2;
> + my $string_arg = $3;
> +
> + $string_arg =~ s/\s+$//;
> + if ($realfile =~ /\.rs$/ && $maybe_excl ne '!') {
> + return;
> + }
> +
> + if ($string_arg !~ /\\n$/ && $string_arg !~ /\n$/) {
> + my $lang = ($realfile =~ /\.rs$/) ? "Rust" : "C";
> + WARN("${lang}_LOG_NO_NEWLINE",
> + "Usage of $macro_call without a trailing newline. Consider adding '\\n'.\n" .
> + $herecurr);
> + }
> + }
> + }
> + }
> +
> +
> # check for .L prefix local symbols in .S files
> if ($realfile =~ /\.S$/ &&
> $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
I couldn't apply this to my tree (with rust-next base), but manually
adding the changes to scripts/checkpatch.pl works as expected.
Alban, can you try resetting your tree to rust-next and apply this
patch? I believe (not sure) there are some indentation issues with the
code.
C. Mitrodimas
next prev parent reply other threads:[~2025-02-07 18:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 12:09 [PATCH v2 RESEND 1/1] checkpatch: add warning for pr_* and dev_* macros without a trailing newline Alban Kurti
2025-02-07 18:19 ` Charalampos Mitrodimas [this message]
2025-02-07 18:40 ` Alban Kurti
-- strict thread matches above, loose matches on Subject: below --
2025-02-06 12:04 Alban Kurti
2025-02-06 12:03 Alban Kurti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m25xllr51m.fsf@posteo.net \
--to=charmitro@posteo.net \
--cc=akpm@linux-foundation.org \
--cc=joe@perches.com \
--cc=kurti@invicto.ai \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox