checkpatch: Check for 0-length and 1-element arrays
PATCH v5 1/1 checkpatch: Check for 0-length and 1-element arrays
Fake flexible arrays have been deprecated since last millennium. Proper C99 flexible arrays must be used throughout the kernel so CONFIG_FORTIFY_SOURCE and CONFIG_UBSAN_BOUNDS can provide proper array bounds checking.
---
v5: - add __packed to outer struct regex too (joe)
v4: https://lore.kernel.org/lkml/[email protected]
v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/lkml/[email protected]
v1: https://lore.kernel.org/lkml/[email protected]
--- scripts/checkpatch.pl | 10 ++++++++++ 1 file changed, 10 insertions(+)
scripts/checkpatch.pl +10 -0
@@ -7430,6 +7430,16 @@ sub process { } } +# 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*\]/[]/; + } + } + # nested likely/unlikely calls if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) { WARN("LIKELY_MISUSE",
Signature · 1 line
2.34.1
Quoted 5 lines · Kees Cook
Fake flexible arrays have been deprecated since last millennium. Proper C99 flexible arrays must be used throughout the kernel so
CONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDScan provide proper array bounds checking.
Quoted 7 lines
Cc Andy Whitcroft <[email protected]>Cc Dwaipayan Ray <[email protected]>Cc Lukas Bulwahn <[email protected]>Fixed-by Joe Perches <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 31 lines
---
v5: - add__packedto outer struct regex too (joe)
v4: https://lore.kernel.org/lkml/[email protected]
v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/lkml/[email protected]
v1: https://lore.kernel.org/lkml/[email protected]--- scripts/checkpatch.pl | 10 ++++++++++ 1 file changed, 10 insertions(+)scripts/checkpatch.pl +10
-0@@ -7430,6 +7430,16 @@ sub process { } } +# 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*\]/[]/; + } + } + # nested likely/unlikely calls if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) { WARN("LIKELY_MISUSE",
Quoted 9 lines · On Thu, 1 Jun 2023 09:07:46 -0700 Kees Cook <[email protected]> wrote:
Fake flexible arrays have been deprecated since last millennium. Proper C99 flexible arrays must be used throughout the kernel so
CONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDScan provide proper array bounds checking.Cc Andy Whitcroft <[email protected]>Cc Dwaipayan Ray <[email protected]>Cc Lukas Bulwahn <[email protected]>Fixed-by Joe Perches <[email protected]>
You didn't checkpatch your checkpatch patch!
WARNING: Non-standard signature: Fixed-by:
#248:
I'll do my usual
[[email protected]: handle __packed for srtucts]
Joe Perches
maintainerQuoted 14 lines · Andrew Morton
Quoted 9 lines · On Thu, 1 Jun 2023 09:07:46 -0700 Kees Cook <[email protected]> wrote:
Fake flexible arrays have been deprecated since last millennium. Proper C99 flexible arrays must be used throughout the kernel so
CONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDScan provide proper array bounds checking.Cc Andy Whitcroft <[email protected]>Cc Dwaipayan Ray <[email protected]>Cc Lukas Bulwahn <[email protected]>Fixed-by Joe Perches <[email protected]>You didn't checkpatch your checkpatch patch!
Quoted 7 lines
WARNING: Non-standard signature: Fixed-by:
#248:Fixed-by Joe Perches <[email protected]>I'll do my usual
[[email protected]: handle
__packedfor srtucts]
With that spelling?
Anyway, I went back and forth a few times with Kees giving suggestions and corrections before sending it on to you for more than just __packed.
I didn't (and still don't) care much about anything other than the code.
cheers, Joe