mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Cryolitia PukNgae <cryolitia@uniontech.com>
Subject: Re: [PATCH v5 4/5] checkpatch: Factor out the check for UAPI files
Date: Wed, 2 Sep 2026 08:09:37 +0200	[thread overview]
Message-ID: <20260902060937.GB890950@pevik> (raw)
In-Reply-To: <20260901105642.851234-5-pvorel@suse.cz>

Hi all,

> DRY.

https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Maybe I should have written that I wanted to follow the same approach as
is_userspace().

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> New in v5.

FYI I tend to drop commit this from v6. Function would make more sense if all
cases were just matching any uapi header via @\binclude/uapi/@.

>  scripts/checkpatch.pl | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index ead35e6abba7..97bf952b0fbc 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2678,6 +2678,11 @@ sub is_userspace {
>  		$realfile =~ m@^arch/.*/tools/@);
>  }

> +sub is_uapi {
> +    my ($realfile) = @_;
> +    return $realfile =~ m@^include/uapi/@;

As sashiko found this was wrong, it should have been using '\b' not '^'.

> +}
> +
>  sub process {
>  	my $filename = shift;

> @@ -4673,7 +4678,7 @@ sub process {
>  				ERROR("MALFORMED_INCLUDE",
>  				      "malformed #include filename\n" . $herecurr);
>  			}
> -			if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
> +			if ($path =~ "^uapi/" && is_uapi($realfile)) {
>  				ERROR("UAPI_INCLUDE",
>  				      "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
>  			}
> @@ -6683,7 +6688,7 @@ sub process {
>  		}

>  # don't use __constant_<foo> functions outside of include/uapi/
> -		if ($realfile !~ m@^include/uapi/@ &&
> +		if (!is_uapi($realfile) &&
>  		    $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
>  			my $constant_func = $1;
>  			my $func = $constant_func;
> @@ -6846,7 +6851,7 @@ sub process {
>  		}

>  # Check for __inline__ and __inline, prefer inline
> -		if ($realfile !~ m@\binclude/uapi/@ &&
> +		if (!is_uapi($realfile) &&
>  		    $line =~ /\b(__inline__|__inline)\b/) {
>  			if (WARN("INLINE",
>  				 "plain inline is preferred over $1\n" . $herecurr) &&
> @@ -6857,7 +6862,7 @@ sub process {
>  		}

>  # Check for compiler attributes
> -		if ($realfile !~ m@\binclude/uapi/@ &&
> +		if (!is_uapi($realfile) &&
>  		    $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) {
>  			my $attr = $1;
>  			$attr =~ s/\s*\(\s*(.*)\)\s*/$1/;
> @@ -6931,7 +6936,7 @@ sub process {
>  		}

>  # check for c99 types like uint8_t used outside of uapi/ and tools/
> -		if ($realfile !~ m@\binclude/uapi/@ &&
> +		if (!is_uapi($realfile) &&
>  		    $realfile !~ m@\btools/@ &&
>  		    $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
>  			my $type = $1;
> @@ -7424,7 +7429,7 @@ sub process {
>  		}

>  # check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
> -		if ($realfile !~ m@^include/uapi/@ &&
> +		if (!is_uapi($realfile) &&

I overlook that regex on BIT() macro is different from the others, matching only
^include/uapi/.  It's a bit surprising for me (shouldn't be all headers checked,
also the arch specific ones and these mirrored into tools/?), but I suppose it's
just me missing something.

Kind regards,
Petr

>  		    $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
>  			my $ull = "";
>  			$ull = "_ULL" if (defined($1) && $1 =~ /ll/i);

  reply	other threads:[~2026-09-02  6:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 10:56 [PATCH v5 0/5] checkpatch: userspace improvements Petr Vorel
2026-09-01 10:56 ` [PATCH v5 1/5] checkpatch: Add more userspace directories to is_userspace() Petr Vorel
2026-09-01 10:56 ` [PATCH v5 2/5] checkpatch: Ignore <inttypes.h> format macros for userspace tools Petr Vorel
2026-09-01 10:56 ` [PATCH v5 3/5] checkpatch: Add --userspace to force userspace rules Petr Vorel
2026-09-01 10:56 ` [PATCH v5 4/5] checkpatch: Factor out the check for UAPI files Petr Vorel
2026-09-02  6:09   ` Petr Vorel [this message]
2026-09-01 10:56 ` [PATCH v5 5/5] checkpatch: Skip kernel specific checks for userspace Petr Vorel
2026-09-02  6:18   ` Petr Vorel
2026-09-01 17:44 ` [PATCH v5 0/5] checkpatch: userspace improvements Andrew Morton
2026-09-02  6:04   ` Petr Vorel

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=20260902060937.GB890950@pevik \
    --to=pvorel@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=cryolitia@uniontech.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /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®