Infinite loop in checkpatch.pl

From: Alexander Potapenko
Date: Fri Mar 03 2023 - 09:28:53 EST


Hi folks,

I've noticed that checkpatch.pl chokes on the following file (also attached):

==================================
$ cat test-checkpatch.txt
diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c
@@ -504,6 +504,25 @@ static void
test_memcpy_aligned_to_unaligned2(struct kunit *test)
+ EXPECTATION_NO_REPORT(expect); \
+ volatile uint##size##_t uninit; \
==================================


, getting into an infinite loop in annotate_values().
The following patch helps it to proceed:

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 78cc595b98ce1..01d998b416a51 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2240,8 +2240,13 @@ sub annotate_values {
print "C($1)\n" if ($dbg_values > 1);
}
if (defined $1) {
- $cur = substr($cur, length($1));
- $res .= $type x length($1);
+ if (length($1)) {
+ $cur = substr($cur, length($1));
+ $res .= $type x length($1);
+ } else {
+ $res .= $cur;
+ $cur = "";
+ }
}
}

, but I have no idea how to test it properly.

Could you please take a look?


Thanks,
Alex

--
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Liana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c
@@ -504,6 +504,25 @@ static void test_memcpy_aligned_to_unaligned2(struct kunit *test)
+ EXPECTATION_NO_REPORT(expect); \
+ volatile uint##size##_t uninit; \