Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Yunseong Kim <yunseong.kim@est.tech>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	gregkh@linuxfoundation.org, sashal@kernel.org
Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	stable@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yunseong Kim <yunseong.kim@ericsson.com>,
	Yunseong Kim <ysk@kzalloc.com>,
	42.4.sejin@gmail.com, Yunseong Kim <yunseong.kim@est.tech>
Subject: [PATCH RESEND] checkpatch: validate upstream commit tags for stable backports
Date: Tue,  5 May 2026 13:23:21 +0200	[thread overview]
Message-ID: <20260505112320.362715-2-yunseong.kim@est.tech> (raw)

According to the stable kernel rules (Option 3), backported patches
should include the upstream commit reference using the SHA1 in one of
two specific formats:

  1. commit <40 length sha1> upstream.
  2. [ Upstream commit <40 length sha1> ]

Currently, checkpatch.pl does not validate these stable-specific
formats, allowing truncated SHA1 characters to pass without notice.

These tags often conflict with the standard GIT_COMMIT_ID rule, which
expects a "12+ chars of sha1" followed by the commit subject in
parentheses. This causes checkpatch to trigger false positive errors.

  ERROR: Please use git commit description style 'commit <12+ chars of sha1> ("<title line>")'
  - ie: 'commit e9acda52fd2e ("bonding: fix use-after-free due to enslave fail after slave array update")
  #9: 
  [ Upstream commit e9acda52fd2ee0cdca332f996da7a95c5fd25294 ]

Add validation to ensure these tags use the required 40-hex-character
SHA1 and provide a warning if the format is malformed. For example:

  WARNING: Malformed 'commit ... upstream.' line - expected 'commit <40 hex chars SHA1> upstream.'
  #7:
  commit e9acda5 upstream.

  WARNING: Malformed '[ Upstream commit ]' line - expected '[ Upstream commit <40 hex chars SHA1> ]'
  #7:
  [ Upstream commit e9acda5 ]

Link: https://docs.kernel.org/process/stable-kernel-rules.html#option-3
Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
---
 scripts/checkpatch.pl | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3727156e4cca..b2058cd93465 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3468,7 +3468,10 @@ sub process {
 
 			if (defined($id) &&
 			    ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&
-			    $last_git_commit_id_linenr != $linenr - 1) {
+				$last_git_commit_id_linenr != $linenr - 1 &&
+				$line !~ /^\s*commit [0-9a-f]+ upstream\b/ &&
+				$line !~ /^\s*\[\s*Upstream commit [0-9a-f]+\s*\]/) {
+
 				ERROR("GIT_COMMIT_ID",
 				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
 			}
@@ -3476,6 +3479,23 @@ sub process {
 			$last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
 		}
 
+# Check '[ Upstream commit <sha1> ]' or 'commit <sha1> upstream.' format in stable patches
+		if ($in_commit_log &&
+		    $line =~ /^\s*commit [0-9a-f]+ upstream\b/) {
+			if ($line !~ /^\s*commit [0-9a-f]{40} upstream\./) {
+				WARN("BAD_UPSTREAM_COMMIT",
+				     "Malformed 'commit ... upstream.' line - expected 'commit <40 hex chars SHA1> upstream.'\n" . $herecurr);
+			}
+		}
+
+		if ($in_commit_log &&
+		    $line =~ /^\s*\[\s*Upstream commit\b/) {
+			if ($line !~ /^\s*\[\s*Upstream commit [0-9a-f]{40}\s*\]/) {
+				WARN("BAD_UPSTREAM_COMMIT",
+				     "Malformed '[ Upstream commit ]' line - expected '[ Upstream commit <40 hex chars SHA1> ]'\n" . $herecurr);
+			}
+		}
+
 # Check for mailing list archives other than lore.kernel.org
 		if ($rawline =~ m{http.*\b$obsolete_archives}) {
 			WARN("PREFER_LORE_ARCHIVE",
-- 
2.43.0


             reply	other threads:[~2026-05-05 11:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05 11:23 Yunseong Kim [this message]
2026-05-05 12:42 ` [PATCH RESEND] checkpatch: validate upstream commit tags for stable backports Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260505112320.362715-2-yunseong.kim@est.tech \
    --to=yunseong.kim@est.tech \
    --cc=42.4.sejin@gmail.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=ysk@kzalloc.com \
    --cc=yunseong.kim@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox