From 3e49a19b17e98eab1f5a4cecaacff3045ac4c25f Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Thu, 26 Dec 2024 19:51:35 -0500 Subject: [PATCH] scripts: checkpatch: add special consideration for DIR DIR is a POSIX type defined via the dirent.h header. In Zephyr, we define it as `typedef void DIR`, since it is only ever described via a pointer (much like `FILE`). However, in checkpatch.pl, functions that return DIR* or accept a DIR* argument are met with an error of the form below: ``` ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) ``` Examples that trigger this false positive are, for example ```cpp int dirfd(DIR *dirp); DIR *fdopendir(int fd); ``` Include `DIR` as a class of specific POSIX types that should be matched as types rather than other tokens. Signed-off-by: Chris Friedt --- scripts/checkpatch.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f942415ed96..27c1f54e54f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -464,10 +464,13 @@ our $typeKernelTypedefs = qr{(?x: (?:__)?(?:u|s|be|le)(?:8|16|32|64)| atomic_t )}; +# DIR is misinterpreted as a macro or value in some POSIX headers +our $typePosixTypedefs = qr{DIR}; our $typeTypedefs = qr{(?x: $typeC99Typedefs\b| $typeOtherOSTypedefs\b| - $typeKernelTypedefs\b + $typeKernelTypedefs\b| + $typePosixTypedefs\b )}; our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};