Re: kernel style preference trivia: '* const' vs '*const' ?

From: Joe Perches
Date: Sun Oct 09 2022 - 17:47:23 EST


On Sun, 2022-10-09 at 18:52 +0200, Miguel Ojeda wrote:
> On Sun, Oct 9, 2022 at 6:21 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
> >
> > The kernel uses '* const' about 10:1 over '*const'
>
> Yeah, going with the most commonly used one sounds best.
>
> clang-format will be able to handle either way with
> `SpaceAroundPointerQualifiers` as soon as the minimum is LLVM 12.

Perhaps the below.

Perhaps it should be a --strict only CHK, but the rest of the const
tests are WARN as well.

---
scripts/checkpatch.pl | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2737e4ced5745..eccd7940eb18b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4605,6 +4605,14 @@ sub process {
}
}

+# check for foo *const, prefer foo * const
+ if ($line =~ /\*const\b/) {
+ if (WARN("POINTER_CONST",
+ "Prefer * const over *const\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\*const\b/* const/;
+ }
+ }
# check for non-global char *foo[] = {"bar", ...} declarations.
if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
WARN("STATIC_CONST_CHAR_ARRAY",