From dcb59dcec4bfaac790d72efb38a5af6526c7dfc1 Mon Sep 17 00:00:00 2001 From: Elyes Haouas Date: Tue, 1 Aug 2023 18:18:32 +0200 Subject: lint/checkpatch: Add check for initialized const char arrays This reduces the difference with linux v6.5-rc4. Change-Id: I9f0e9f12a177c32b401fda74cbb30c5c259b3744 Signed-off-by: Elyes Haouas Reviewed-on: https://review.coreboot.org/c/coreboot/+/70201 Tested-by: build bot (Jenkins) Reviewed-by: Martin L Roth --- util/lint/checkpatch.pl | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'util/lint') diff --git a/util/lint/checkpatch.pl b/util/lint/checkpatch.pl index 91cf2da840..21704ac74b 100755 --- a/util/lint/checkpatch.pl +++ b/util/lint/checkpatch.pl @@ -4221,6 +4221,15 @@ sub process { $herecurr); } +# check for initialized const char arrays that should be static const + if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) { + if (WARN("STATIC_CONST_CHAR_ARRAY", + "const array should probably be static const\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/; + } + } + # check for static char foo[] = "bar" declarations. if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { WARN("STATIC_CONST_CHAR_ARRAY", -- cgit v1.2.3