Code that puts a single dereferencing identifier on multiple lines like:

     struct_identifier->member[index].
        member = <foo>;

is generally hard to follow.

Prefer that dereferencing identifiers be single line.

Signed-off-by: Joe Perches <[email protected]>
---
 scripts/checkpatch.pl | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index fdacd759078e..22abb4af5b4f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3440,6 +3440,18 @@ sub process {
 #ignore lines not being added
                next if ($line =~ /^[^\+]/);
 
+# check for dereferences that span multiple lines
+               if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
+                   $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
+                       $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
+                       my $ref = $1;
+                       $line =~ /^.\s*($Lval)/;
+                       $ref .= $1;
+                       $ref =~ s/\s//g;
+                       WARN("MULTILINE_DEREFERENCE",
+                            "Avoid multiple line dereference - prefer 
'$ref'\n" . $hereprev);
+               }
+
 # check for declarations of signed or unsigned without int
                while ($line =~ 
m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
                        my $type = $1;
-- 
2.10.0.rc2.1.g053435c

Reply via email to