[Linux-kernel-mentees] [PATCH] checkpatch: add fix option for BAD_SIGN_OFF

Aditya Srivastava yashsri421 at gmail.com
Tue Dec 8 17:52:56 UTC 2020


Currently checkpatch warns us if the Co-developed-by line for an author
isn't immediately followed by the Signed-off-by line.

Generally, this warning occurs because of:
1) Absence of Signed-off-by line for the author from the patch
2) Misplaced Signed-off-by line for the author in the patch

Provide a simple fix by:
1) Inserting Signed-off-by line for the author immediately after the
Co-developed-by line

2) Removing Signed-off-by line for the author (if it pre-existed on
some other line)

Suggested-by: Lukas Bulwahn <lukas.bulwahn at gmail.com>
Signed-off-by: Aditya Srivastava <yashsri421 at gmail.com>
---
 scripts/checkpatch.pl | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ca5bb5a3f8f6..8bd8e4518f7f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2496,6 +2496,9 @@ sub process {
 	my @setup_docs = ();
 	my $setup_docs = 0;
 
+	my %signed_off_by_lines;
+	my %co_developed_by_lines;
+
 	my $camelcase_file_seeded = 0;
 
 	my $checklicenseline = 1;
@@ -2781,6 +2784,7 @@ sub process {
 					my $ctx = $1;
 					my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
 					my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
+					$signed_off_by_lines{$ctx} = $fixlinenr;
 
 					if ($email_address eq $author_address && $email_name eq $author_name) {
 						$author_sob = $ctx;
@@ -2972,11 +2976,17 @@ sub process {
 					      "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline);
 				}
 				if (!defined $lines[$linenr]) {
-					WARN("BAD_SIGN_OFF",
-                                             "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
+					if (WARN("BAD_SIGN_OFF",
+						 "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline) &&
+					    $fix) {
+						$co_developed_by_lines{$email} = $fixlinenr;
+					}
 				} elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
-					WARN("BAD_SIGN_OFF",
-					     "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
+					if (WARN("BAD_SIGN_OFF",
+						 "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]) &&
+					    $fix) {
+						$co_developed_by_lines{$email} = $fixlinenr;
+					}
 				} elsif ($1 ne $email) {
 					WARN("BAD_SIGN_OFF",
 					     "Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
@@ -7238,6 +7248,16 @@ sub process {
 		ERROR("NOT_UNIFIED_DIFF",
 		      "Does not appear to be a unified-diff format patch\n");
 	}
+
+	if (%co_developed_by_lines) {
+		foreach my $co_developer (keys %co_developed_by_lines) {
+			if (exists($signed_off_by_lines{$co_developer})) {
+				fix_delete_line($signed_off_by_lines{$co_developer}, "Signed-off-by: $co_developer");
+			}
+			fix_insert_line($co_developed_by_lines{$co_developer} + 1, "Signed-off-by: $co_developer");
+		}
+	}
+
 	if ($is_patch && $has_commit_log && $chk_signoff) {
 		if ($signoff == 0) {
 			ERROR("MISSING_SIGN_OFF",
-- 
2.17.1



More information about the Linux-kernel-mentees mailing list