linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH] checkpatch: add fix option for BAD_SIGN_OFF
@ 2020-12-02 18:36 Aditya Srivastava
  2020-12-08 16:44 ` Aditya
  0 siblings, 1 reply; 9+ messages in thread
From: Aditya Srivastava @ 2020-12-02 18:36 UTC (permalink / raw)
  To: lukas.bulwahn; +Cc: linux-kernel-mentees

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@gmail.com>
Signed-off-by: Aditya Srivastava <yashsri421@gmail.com>
---
 scripts/checkpatch.pl | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5c9f13a97c12..d8f9d4d8b13d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2509,6 +2509,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;
@@ -2794,6 +2797,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;
@@ -2989,11 +2993,17 @@ sub process {
 					}
 				}
 				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]);
@@ -7203,6 +7213,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

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-12 10:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 18:36 [Linux-kernel-mentees] [PATCH] checkpatch: add fix option for BAD_SIGN_OFF Aditya Srivastava
2020-12-08 16:44 ` Aditya
2020-12-08 16:54   ` Lukas Bulwahn
2020-12-08 17:44     ` Aditya
2020-12-08 17:52       ` Aditya Srivastava
2020-12-08 21:07       ` Lukas Bulwahn
2020-12-09 11:46         ` Aditya
2020-12-09 11:51           ` Lukas Bulwahn
2020-12-12 10:55             ` Aditya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).