mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alban Kurti <kurti@invicto.ai>
To: Charalampos Mitrodimas <charmitro@posteo.net>
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:40:31 +0000 (UTC)	[thread overview]
Message-ID: <7e664d9e0f957206cdc70fb7f178df709fe4d936.camel@invicto.ai> (raw)
In-Reply-To: <m25xllr51m.fsf@posteo.net>

Hi Charalampos,

Thank you for testing.

I just send v4, ignore v3 please. It should fix the formatting issue,
additionally, I thought of implementing a new feature further as I
think it can enhance the functionality, but I can always revert to the
v2 approach if it is deemed to complicated or unnecessary.

Kind regards,
Alban Kurti

On Fri, 2025-02-07 at 18:19 +0000, Charalampos Mitrodimas wrote:
> 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


  reply	other threads:[~2025-02-07 18:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 12:09 Alban Kurti
2025-02-07 18:19 ` Charalampos Mitrodimas
2025-02-07 18:40   ` Alban Kurti [this message]
  -- 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=7e664d9e0f957206cdc70fb7f178df709fe4d936.camel@invicto.ai \
    --to=kurti@invicto.ai \
    --cc=akpm@linux-foundation.org \
    --cc=charmitro@posteo.net \
    --cc=joe@perches.com \
    --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

all inboxes | Powered by JetHome®