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

Geert Uytterhoeven posted 1 patch 4 months ago
There is a newer version of this series
usr/include/headers_check.pl | 3 +++
1 file changed, 3 insertions(+)
[PATCH] kbuild: uapi: Strip comments before size type check
Posted by Geert Uytterhoeven 4 months 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>
---
 usr/include/headers_check.pl | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
index 21c2fb9520e6af2d..75dfdce39e7f4610 100755
--- a/usr/include/headers_check.pl
+++ b/usr/include/headers_check.pl
@@ -155,6 +155,9 @@ sub check_sizetypes
 	if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
 		check_include_typesh($included);
 	}
+	# strip comments (single-line and C99 only)
+	$line =~ s@\/\*.*?\*\/@@;
+	$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] kbuild: uapi: Strip comments before size type check
Posted by Thomas Weißschuh 4 months ago
On Mon, Oct 06, 2025 at 10:49:28AM +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.

This commit has been in -next for some time. Any idea why the issue did
not show up there?

> 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>

> ---
>  usr/include/headers_check.pl | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
> index 21c2fb9520e6af2d..75dfdce39e7f4610 100755
> --- a/usr/include/headers_check.pl
> +++ b/usr/include/headers_check.pl
> @@ -155,6 +155,9 @@ sub check_sizetypes
>  	if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
>  		check_include_typesh($included);
>  	}
> +	# strip comments (single-line and C99 only)
> +	$line =~ s@\/\*.*?\*\/@@;
> +	$line =~ s@\/\/.*$@@;

C99/C++ comments are rejected in UAPI headers, so this line can be dropped.

>  	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] kbuild: uapi: Strip comments before size type check
Posted by Geert Uytterhoeven 4 months ago
Hi Thomas,

On Mon, 6 Oct 2025 at 12:31, Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
> On Mon, Oct 06, 2025 at 10:49:28AM +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.
>
> This commit has been in -next for some time. Any idea why the issue did
> not show up there?

No idea. Looks like the build bots that are still running don't exercise m68k
builds on linux-next?
Perhaps this is just collateral damage of the loss of the kisskb build service?

> > 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>

Thanks!

>
> > ---
> >  usr/include/headers_check.pl | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
> > index 21c2fb9520e6af2d..75dfdce39e7f4610 100755
> > --- a/usr/include/headers_check.pl
> > +++ b/usr/include/headers_check.pl
> > @@ -155,6 +155,9 @@ sub check_sizetypes
> >       if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
> >               check_include_typesh($included);
> >       }
> > +     # strip comments (single-line and C99 only)
> > +     $line =~ s@\/\*.*?\*\/@@;
> > +     $line =~ s@\/\/.*$@@;
>
> C99/C++ comments are rejected in UAPI headers, so this line can be dropped.

'git grep "//" -- "*uapi*.h"' disagrees...

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] kbuild: uapi: Strip comments before size type check
Posted by Thomas Weißschuh 4 months ago
On Mon, Oct 06, 2025 at 01:22:01PM +0200, Geert Uytterhoeven wrote:

(...)

> > > diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
> > > index 21c2fb9520e6af2d..75dfdce39e7f4610 100755
> > > --- a/usr/include/headers_check.pl
> > > +++ b/usr/include/headers_check.pl
> > > @@ -155,6 +155,9 @@ sub check_sizetypes
> > >       if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
> > >               check_include_typesh($included);
> > >       }
> > > +     # strip comments (single-line and C99 only)
> > > +     $line =~ s@\/\*.*?\*\/@@;
> > > +     $line =~ s@\/\/.*$@@;
> >
> > C99/C++ comments are rejected in UAPI headers, so this line can be dropped.
> 
> 'git grep "//" -- "*uapi*.h"' disagrees...

The ones I see from this call are either
a) in tools/
b) within a larger /* */ block
c) in URLs (http://...)
d) in headers which are not real UAPI headers (drivers/staging/gpib/uapi/gpib_ioctl.h)
e) ignored by the header check tools (include/uapi/linux/coda.h)

The UAPI headers are checked against -std=c90 which does not allow C99 comments.
See usr/include/Makefile.


Thomas