2024-03-06 09:34:24

by Lukas Bulwahn

[permalink] [raw]
Subject: checkpatch.pl getting stuck on a macro in mm/kmsan/kmsan_test.c

Dear Joe,

while running checkpatch.pl -f on all files in the kernel repository
(v6.8-rc1) for some experiment, I noticed that checkpatch.pl got stuck
on mm/kmsan/kmsan_test.c, i.e., ./scripts/checkpatch.pl -f
mm/kmsan/kmsan_test.c never terminates.

I could already boil it down to checkpatch getting stuck on the macro
#define DEFINE_TEST_MEMSETXX(size), see lines 541 to 554 in
mm/kmsan/kmsan_test.c on v6.8-rc1.

I do not know if it is worth fixing, but certainly I was surprised
that reasonable code can put checkpatch into some stuck state.

Best regards,

Lukas


2024-03-06 15:13:17

by Dan Carpenter

[permalink] [raw]
Subject: Re: checkpatch.pl getting stuck on a macro in mm/kmsan/kmsan_test.c

On Wed, Mar 06, 2024 at 10:33:55AM +0100, Lukas Bulwahn wrote:
> Dear Joe,
>
> while running checkpatch.pl -f on all files in the kernel repository
> (v6.8-rc1) for some experiment, I noticed that checkpatch.pl got stuck
> on mm/kmsan/kmsan_test.c, i.e., ./scripts/checkpatch.pl -f
> mm/kmsan/kmsan_test.c never terminates.
>
> I could already boil it down to checkpatch getting stuck on the macro
> #define DEFINE_TEST_MEMSETXX(size), see lines 541 to 554 in
> mm/kmsan/kmsan_test.c on v6.8-rc1.
>
> I do not know if it is worth fixing, but certainly I was surprised
> that reasonable code can put checkpatch into some stuck state.

I think the bug is ancient... Here is a stupid solution. But afterward
it still prints a ton of Perl warnings:

substr outside of string at ./scripts/checkpatch.pl line 5158.
Use of uninitialized value $op_type in string ne at ./scripts/checkpatch.pl line 5164.
substr outside of string at ./scripts/checkpatch.pl line 5158.
Use of uninitialized value $op_type in string ne at ./scripts/checkpatch.pl line 5164.

regards,
dan carpenter

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9c4c4a61bc83..bd7a286bc1ce 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2260,10 +2260,14 @@ sub annotate_values {
} elsif ($cur =~ /(^.)/o) {
print "C($1)\n" if ($dbg_values > 1);
}
+ my $old = $cur;
if (defined $1) {
$cur = substr($cur, length($1));
$res .= $type x length($1);
}
+ if ($old eq $cur) {
+ last;
+ }
}

return ($res, $var);



2024-03-07 17:50:37

by Joe Perches

[permalink] [raw]
Subject: Re: checkpatch.pl getting stuck on a macro in mm/kmsan/kmsan_test.c

On Wed, 2024-03-06 at 10:33 +0100, Lukas Bulwahn wrote:
> Dear Joe,
>
> while running checkpatch.pl -f on all files in the kernel repository
> (v6.8-rc1) for some experiment, I noticed that checkpatch.pl got stuck
> on mm/kmsan/kmsan_test.c, i.e., ./scripts/checkpatch.pl -f
> mm/kmsan/kmsan_test.c never terminates.
>
> I could already boil it down to checkpatch getting stuck on the macro
> #define DEFINE_TEST_MEMSETXX(size), see lines 541 to 554 in
> mm/kmsan/kmsan_test.c on v6.8-rc1.
>
> I do not know if it is worth fixing, but certainly I was surprised
> that reasonable code can put checkpatch into some stuck state.
>

I know why it hangs. I'll give it a think for a bit.
I rather doubt Dan's suggestion is the appropriate one.

Code is:

volatile uint##size##_t
uninit; \

and in checkpatch line 2304:

$possible =~ s/\s*$Type\s*//g;

where uint is a $Type it removes.