[PATCH v2] kbuild: uapi: Strip comments before size type check

Geert Uytterhoeven posted 1 patch 2 months, 1 week ago
usr/include/headers_check.pl | 2 ++
1 file changed, 2 insertions(+)
[PATCH v2] kbuild: uapi: Strip comments before size type check
Posted by Geert Uytterhoeven 2 months, 1 week ago
On m68k, check_sizetypes in headers_check reports:

    ./usr/include/asm/bootinfo-amiga.h:17: found __[us]{8,16,32,64} type without #include <linux/types.h>

This header file does not use any of the Linux-specific integer types,
but merely refers to them from comments, so this is a false positive.
As of commit c3a9d74ee413bdb3 ("kbuild: uapi: upgrade check_sizetypes()
warning to error"), this check was promoted to an error, breaking m68k
all{mod,yes}config builds.

Fix this by stripping simple comments before looking for Linux-specific
integer types.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
v2:
  - Add Reviewed-by,
  - Drop support for C99 comments.
---
 usr/include/headers_check.pl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
index 21c2fb9520e6af2d..16c238aadfebb061 100755
--- a/usr/include/headers_check.pl
+++ b/usr/include/headers_check.pl
@@ -155,6 +155,8 @@ sub check_sizetypes
 	if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
 		check_include_typesh($included);
 	}
+	# strip comments (single-line only)
+	$line =~ s@\/\*.*?\*\/@@;
 	if ($line =~ m/__[us](8|16|32|64)\b/) {
 		printf STDERR "$filename:$lineno: " .
 		              "found __[us]{8,16,32,64} type " .
-- 
2.43.0

Re: [PATCH v2] kbuild: uapi: Strip comments before size type check
Posted by Nathan Chancellor 2 months, 1 week ago
On Mon, 06 Oct 2025 14:33:42 +0200, Geert Uytterhoeven wrote:
> On m68k, check_sizetypes in headers_check reports:
> 
>     ./usr/include/asm/bootinfo-amiga.h:17: found __[us]{8,16,32,64} type without #include <linux/types.h>
> 
> This header file does not use any of the Linux-specific integer types,
> but merely refers to them from comments, so this is a false positive.
> As of commit c3a9d74ee413bdb3 ("kbuild: uapi: upgrade check_sizetypes()
> warning to error"), this check was promoted to an error, breaking m68k
> all{mod,yes}config builds.
> 
> [...]

Applied, thanks!

[1/1] kbuild: uapi: Strip comments before size type check
      https://git.kernel.org/kbuild/c/66128f4287b04

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>
Re: [PATCH v2] kbuild: uapi: Strip comments before size type check
Posted by Andreas Schwab 2 months, 1 week ago
On Okt 06 2025, Geert Uytterhoeven wrote:

> diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
> index 21c2fb9520e6af2d..16c238aadfebb061 100755
> --- a/usr/include/headers_check.pl
> +++ b/usr/include/headers_check.pl
> @@ -155,6 +155,8 @@ sub check_sizetypes
>  	if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
>  		check_include_typesh($included);
>  	}
> +	# strip comments (single-line only)
> +	$line =~ s@\/\*.*?\*\/@@;

I don't think you need to quote the forward slashes in the regexp.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Re: [PATCH v2] kbuild: uapi: Strip comments before size type check
Posted by Geert Uytterhoeven 2 months, 1 week ago
Hi Andreas,

On Mon, 6 Oct 2025 at 14:40, Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Okt 06 2025, Geert Uytterhoeven wrote:
> > --- a/usr/include/headers_check.pl
> > +++ b/usr/include/headers_check.pl
> > @@ -155,6 +155,8 @@ sub check_sizetypes
> >       if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
> >               check_include_typesh($included);
> >       }
> > +     # strip comments (single-line only)
> > +     $line =~ s@\/\*.*?\*\/@@;
>
> I don't think you need to quote the forward slashes in the regexp.

Thanks, you are right!

So far for not just following my instinct, but looking for similar functionality
in other scripts like scripts/kernel-doc.pl...

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH v2] kbuild: uapi: Strip comments before size type check
Posted by Nathan Chancellor 2 months, 1 week ago
Hi Geert,

On Mon, Oct 06, 2025 at 03:20:52PM +0200, Geert Uytterhoeven wrote:
> On Mon, 6 Oct 2025 at 14:40, Andreas Schwab <schwab@linux-m68k.org> wrote:
> > On Okt 06 2025, Geert Uytterhoeven wrote:
> > > --- a/usr/include/headers_check.pl
> > > +++ b/usr/include/headers_check.pl
> > > @@ -155,6 +155,8 @@ sub check_sizetypes
> > >       if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
> > >               check_include_typesh($included);
> > >       }
> > > +     # strip comments (single-line only)
> > > +     $line =~ s@\/\*.*?\*\/@@;
> >
> > I don't think you need to quote the forward slashes in the regexp.
> 
> Thanks, you are right!
> 
> So far for not just following my instinct, but looking for similar functionality
> in other scripts like scripts/kernel-doc.pl...

I will fix this up when applying. I think I am going to adjust the
comment to

  # strip single-line comments, as types may be referenced within them

just to be a little more verbose about why it is being done.

Sorry for the breakage!

Cheers,
Nathan
Re: [PATCH v2] kbuild: uapi: Strip comments before size type check
Posted by Geert Uytterhoeven 2 months, 1 week ago
Hi Nathan,

On Mon, 6 Oct 2025 at 20:02, Nathan Chancellor <nathan@kernel.org> wrote:
> On Mon, Oct 06, 2025 at 03:20:52PM +0200, Geert Uytterhoeven wrote:
> > On Mon, 6 Oct 2025 at 14:40, Andreas Schwab <schwab@linux-m68k.org> wrote:
> > > On Okt 06 2025, Geert Uytterhoeven wrote:
> > > > --- a/usr/include/headers_check.pl
> > > > +++ b/usr/include/headers_check.pl
> > > > @@ -155,6 +155,8 @@ sub check_sizetypes
> > > >       if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
> > > >               check_include_typesh($included);
> > > >       }
> > > > +     # strip comments (single-line only)
> > > > +     $line =~ s@\/\*.*?\*\/@@;
> > >
> > > I don't think you need to quote the forward slashes in the regexp.
> >
> > Thanks, you are right!
> >
> > So far for not just following my instinct, but looking for similar functionality
> > in other scripts like scripts/kernel-doc.pl...
>
> I will fix this up when applying. I think I am going to adjust the
> comment to
>
>   # strip single-line comments, as types may be referenced within them
>
> just to be a little more verbose about why it is being done.

OK, thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds