History

checkpatch: add new warnings to author signoff checks.

The author signed-off-by checks are currently very vague. Cases like same name or same address are not handled separately. For example, running checkpatch on commit be6577af0cef ("parisc: Add atomic64_set_release() define to avoid CPU soft lockups"), gives: WARNING: Missing Signed-off-by: line by nominal patch author 'John David Anglin <dave.anglin@bell.net>' The signoff line was: "Signed-off-by: Dave Anglin <dave.anglin@bell.net>" Clearly the author has signed off but with a slightly different version of his name. A more appropriate warning would have been to point out at the name mismatch instead. Previously, the values assumed by $authorsignoff were either 0 or 1 to indicate whether a proper sign off by author is present. Extended the checks to handle four new cases. $authorsignoff values now denote the following: 0: Missing sign off by patch author. 1: Sign off present and identical. 2: Addresses and names match, but comments differ. "James Watson(JW) <james@gmail.com>", "James Watson <james@gmail.com>" 3: Addresses match, but names are different. "James Watson <james@gmail.com>", "James <james@gmail.com>" 4: Names match, but addresses are different. "James Watson <james@watson.com>", "James Watson <james@gmail.com>" 5: Names match, addresses excluding subaddress details (RFC 5233) match. "James Watson <james@gmail.com>", "James Watson <james+a@gmail.com>" Also introduced a new message type FROM_SIGN_OFF_MISMATCH for cases 2, 3, 4 and 5.

Dwaipayan Ray committed 6 years ago

Commit 48ca2d81 parent c70735c1 file · +77 −16Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+77−16
@@ -1181,10 +1181,10 @@ sub parse_email { · 1180 unmodified lines
11811181 }
11821182 }
11831183
1184+ $comment = trim($comment);
11841185 $name = trim($name);
11851186 $name =~ s/^\"|\"$//g;
1186− $name =~ s/(\s*\([^\)]+\))\s*//;
1187− if (defined($1)) {
1187+ if ($name =~ s/(\s*\([^\)]+\))\s*//) {
11881188 $name_comment = trim($1);
11891189 }
11901190 $address = trim($address);
@@ -1199,10 +1199,12 @@ sub parse_email { · 8 unmodified lines
11991199 }
12001200
12011201 sub format_email {
1202− my ($name, $address) = @_;
1202+ my ($name, $name_comment, $address, $comment) = @_;
12031203
12041204 my $formatted_email;
12051205
1206+ $name_comment = trim($name_comment);
1207+ $comment = trim($comment);
12061208 $name = trim($name);
12071209 $name =~ s/^\"|\"$//g;
12081210 $address = trim($address);
@@ -1215,9 +1217,9 @@ sub format_email { · 6 unmodified lines
12151217 if ("$name" eq "") {
12161218 $formatted_email = "$address";
12171219 } else {
1218− $formatted_email = "$name <$address>";
1220+ $formatted_email = "$name$name_comment <$address>";
12191221 }
1220−
1222+ $formatted_email .= "$comment";
12211223 return $formatted_email;
12221224 }
12231225
@@ -1225,17 +1227,23 @@ sub reformat_email { · 1 unmodified line
12251227 my ($email) = @_;
12261228
12271229 my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
1228− return format_email($email_name, $email_address);
1230+ return format_email($email_name, $name_comment, $email_address, $comment);
12291231 }
12301232
12311233 sub same_email_addresses {
1232− my ($email1, $email2) = @_;
1234+ my ($email1, $email2, $match_comment) = @_;
12331235
12341236 my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);
12351237 my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2);
12361238
1239+ if ($match_comment != 1) {
1240+ return $email1_name eq $email2_name &&
1241+ $email1_address eq $email2_address;
1242+ }
12371243 return $email1_name eq $email2_name &&
1238− $email1_address eq $email2_address;
1244+ $email1_address eq $email2_address &&
1245+ $name1_comment eq $name2_comment &&
1246+ $comment1 eq $comment2;
12391247 }
12401248
12411249 sub which {
@@ -2365,6 +2373,7 @@ sub process { · 1123 unmodified lines
23652373 my $signoff = 0;
23662374 my $author = '';
23672375 my $authorsignoff = 0;
2376+ my $author_sob = '';
23682377 my $is_patch = 0;
23692378 my $is_binding_patch = -1;
23702379 my $in_header_lines = $file ? 0 : 1;
@@ -2692,9 +2701,37 @@ sub process { · 321 unmodified lines
26922701 if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
26932702 $signoff++;
26942703 $in_commit_log = 0;
2695− if ($author ne '') {
2696− if (same_email_addresses($1, $author)) {
2704+ if ($author ne '' && $authorsignoff != 1) {
2705+ if (same_email_addresses($1, $author, 1)) {
26972706 $authorsignoff = 1;
2707+ } else {
2708+ my $ctx = $1;
2709+ my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
2710+ my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
2711+
2712+ if ($email_address eq $author_address && $email_name eq $author_name) {
2713+ $author_sob = $ctx;
2714+ $authorsignoff = 2;
2715+ } elsif ($email_address eq $author_address) {
2716+ $author_sob = $ctx;
2717+ $authorsignoff = 3;
2718+ } elsif ($email_name eq $author_name) {
2719+ $author_sob = $ctx;
2720+ $authorsignoff = 4;
2721+
2722+ my $address1 = $email_address;
2723+ my $address2 = $author_address;
2724+
2725+ if ($address1 =~ /(\S+)\+\S+(\@.*)/) {
2726+ $address1 = "$1$2";
2727+ }
2728+ if ($address2 =~ /(\S+)\+\S+(\@.*)/) {
2729+ $address2 = "$1$2";
2730+ }
2731+ if ($address1 eq $address2) {
2732+ $authorsignoff = 5;
2733+ }
2734+ }
26982735 }
26992736 }
27002737 }
@@ -2751,7 +2788,7 @@ sub process { · 50 unmodified lines
27512788 }
27522789
27532790 my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
2754− my $suggested_email = format_email(($email_name, $email_address));
2791+ my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment));
27552792 if ($suggested_email eq "") {
27562793 ERROR("BAD_SIGN_OFF",
27572794 "Unrecognized email address: '$email'\n" . $herecurr);
@@ -2761,9 +2798,9 @@ sub process { · 3 unmodified lines
27612798 $dequoted =~ s/" </ </;
27622799 # Don't force email to have quotes
27632800 # Allow just an angle bracketed address
2764− if (!same_email_addresses($email, $suggested_email)) {
2801+ if (!same_email_addresses($email, $suggested_email, 0)) {
27652802 WARN("BAD_SIGN_OFF",
2766− "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
2803+ "email address '$email' might be better as '$suggested_email'\n" . $herecurr);
27672804 }
27682805 }
27692806
@@ -6943,9 +6980,33 @@ sub process { · 4173 unmodified lines
69436980 if ($signoff == 0) {
69446981 ERROR("MISSING_SIGN_OFF",
69456982 "Missing Signed-off-by: line(s)\n");
6946− } elsif (!$authorsignoff) {
6947− WARN("NO_AUTHOR_SIGN_OFF",
6948− "Missing Signed-off-by: line by nominal patch author '$author'\n");
6983+ } elsif ($authorsignoff != 1) {
6984+ # authorsignoff values:
6985+ # 0 -> missing sign off
6986+ # 1 -> sign off identical
6987+ # 2 -> names and addresses match, comments mismatch
6988+ # 3 -> addresses match, names different
6989+ # 4 -> names match, addresses different
6990+ # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
6991+
6992+ my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
6993+
6994+ if ($authorsignoff == 0) {
6995+ ERROR("NO_AUTHOR_SIGN_OFF",
6996+ "Missing Signed-off-by: line by nominal patch author '$author'\n");
6997+ } elsif ($authorsignoff == 2) {
6998+ CHK("FROM_SIGN_OFF_MISMATCH",
6999+ "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
7000+ } elsif ($authorsignoff == 3) {
7001+ WARN("FROM_SIGN_OFF_MISMATCH",
7002+ "From:/Signed-off-by: email name mismatch: $sob_msg\n");
7003+ } elsif ($authorsignoff == 4) {
7004+ WARN("FROM_SIGN_OFF_MISMATCH",
7005+ "From:/Signed-off-by: email address mismatch: $sob_msg\n");
7006+ } elsif ($authorsignoff == 5) {
7007+ WARN("FROM_SIGN_OFF_MISMATCH",
7008+ "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
7009+ }
69497010 }
69507011 }
69517012