diff options
author | Elyes Haouas <ehaouas@noos.fr> | 2023-08-01 17:53:42 +0200 |
---|---|---|
committer | Elyes Haouas <ehaouas@noos.fr> | 2023-08-09 20:42:08 +0000 |
commit | 281d6623f276b3b7840981b9dfee1b44530ba84c (patch) | |
tree | 7dda6b85a58203649bc29d49771c7be441cb75b3 /util/lint | |
parent | b8c0e326a3dbcd9c526b9d7fb9756b8c9f4ac6b4 (diff) |
lint/checkpatch.pl: Check for 0-length and 1-element arrays
Use C99 flexible arrays instead of deprecated fake flexible arrays.
This reduce difference with upstream.
Change-Id: I24016493280e22f34ae5cce49fe7c1f520270f9a
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/76869
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin L Roth <gaumless@gmail.com>
Diffstat (limited to 'util/lint')
-rwxr-xr-x | util/lint/checkpatch.pl | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/util/lint/checkpatch.pl b/util/lint/checkpatch.pl index c4e9ac8e41..bda7b31d88 100755 --- a/util/lint/checkpatch.pl +++ b/util/lint/checkpatch.pl @@ -6897,6 +6897,16 @@ sub process { "Using $1 should generally have parentheses around the comparison\n" . $herecurr); } +# check for array definition/declarations that should use flexible arrays instead + if ($sline =~ /^[\+ ]\s*\}(?:\s*__packed)?\s*;\s*$/ && + $prevline =~ /^\+\s*(?:\}(?:\s*__packed\s*)?|$Type)\s*$Ident\s*\[\s*(0|1)\s*\]\s*;\s*$/) { + if (ERROR("FLEXIBLE_ARRAY", + "Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays\n" . $hereprev) && + $1 == '0' && $fix) { + $fixed[$fixlinenr - 1] =~ s/\[\s*0\s*\]/[]/; + } + } + # whine mightly about in_atomic if ($line =~ /\bin_atomic\s*\(/) { if ($realfile =~ m@^drivers/@) { |