From nobody Thu Apr 2 22:46:23 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10FA725776 for ; Thu, 26 Mar 2026 06:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774506041; cv=none; b=jN7ZLKkrl9eZkdNNDWeo0vCYkcu2TnEW64eSiTqWrKQ74FXpjdBcAjJg29upPBPVYqP/0+gLtejqwryzROSogaoytu+XkTTtDC21f+3hNwfkcnEJZcrDbDu6Tkhayi/WQWP3rfNcfcYwP8tjn6PW8dnY34FOIrJ227PiMCwQAY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774506041; c=relaxed/simple; bh=br/jwXyKsOgF8QpG+OEMmn/wjLJg+ymOyi2ueX2+2uA=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=jR+3MkFBNzgTvi2ONSO34cb0rtmFxz6lcG0YJWF4bklyxoA8ATIMsW1SLhlwKTVzFbVYdlmZCXy8+DLxy36KGkv4g2PZetyVp6TJAdrr8Oqgka/Ox7cyeSJa3jjWcPdupwyl4J5syU19Y0DR8zHCw1lTcPtswXT9cPQFq/K5Qrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Owp7F8af; arc=none smtp.client-ip=74.125.82.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Owp7F8af" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-12732e6a123so1706525c88.1 for ; Wed, 25 Mar 2026 23:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774506039; x=1775110839; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=VofYlHZ2Eo1t9FKVicPQrSRmzPkyfNodwvF5CvNMdtk=; b=Owp7F8afms/+Pn2vqioDtJJxj7hTFuRkb3f37mdZ/ThwYceMufrtLB8U3rtExIs3dF 81xzx0iF2NCMXx3ZOyRyA+8BktgwVGUkXdWP67CuN6eHcFvwjP2c1oVra+0tdxJAtg/b +y5Ej1rrJljJN8yHP2fJnKrZTKZma8OVj/GcbgqNKRAoziuqVRIGzdg3lsHzZlb+U+oB +xndyP31pIuUGuZqDij8Nxyzh2eGPwzOskjFIafyn2TnF0bGDLuDFSR+9W3knuMSDfMl KBvrh2BqHfHmM6/bZ1A5NTfnVKNxlzx1jxPmUEPCj4IpHrYUw2JiOHSQjVlSEy2Nmc4G S53w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774506039; x=1775110839; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VofYlHZ2Eo1t9FKVicPQrSRmzPkyfNodwvF5CvNMdtk=; b=E00lbTFb2yzKQ3uSbqo5Yj3Z13hHN8VlxtQSjHLL1CM5CqL/b6DYYwmTypaX9mknVH syjdIlfSf85pkFbE3QvMyQ/wKbfIgz58Aq8G0QlLV/gOTSB58Et6AoLzCobmaTL3vSW4 EKs+VnWS8VxlZAwcf6ljRKlWRnWjE0r5yaB5aoScvimMMuy1R5y5No4QImxebt8IaCeV M9/xh7NK6NwTuBemj4ppjIeCkBP/i4XeuHv6VqWrPqQAdTzLR6UQ8CN3Kcu69Th6cQsW qhBDKJXC6pDFL2kwVJqtZ8wVbGhHcEXcSWez6UMFzDnSrHJVAL4FfHDhrJ6WgJP+3At8 n9rA== X-Forwarded-Encrypted: i=1; AJvYcCVR/HAKYiUrgLXq7I5neYt+shMP6x4sTSmq21sCf7lS+2en2KJYkgB8PFqHmN4AQGHWTsJAB+eUqKoy2Tk=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu/GZxZmjbG3axnfIcE94FnlloM6nnPfN27CXUd17LW64Pjppu jTZNrowIsEWU92lwRhMYvsKXx7kWdw3LuxCvBSFnjNOlADB2MRsxh9Z0 X-Gm-Gg: ATEYQzxVYMyitIjFjfcJuT8FRgj5j4T+u9tPKZKmraTbeHA3kYmyMGrUH+alVpLMTxI 5YfZJGyqGUQwNOBRXofQQWfCw9r4PsXS8dZkYVGkGyBl0VXQk8J0EO+Iu69Spach+9jpXUCi829 Ni+9mcqxHSZHTi8w2JC37VUgxanGPTsWizU34hPk8yBbOo+FD/GzmjMJbrBGqQ8dG9BU6/9K5QA I/fhB2Hof9rwSlWU4wVJQ02fVkBKQ+H0X94Db07VgN0DoylJZlgKFm6rCQubJY1a8v9WkT8bToT I+zVhPWdNndCKJM/yNJeGgdEMyQ0hnvNPvrkhE183lldNaM+eNLRJPctnGNaPpK80x5X7WpwsJu dC4QDS+Pwmb6DdU8LTl4qMGmETFXheaXEgA8VrY1FB4ElEIshVPk/vTe8guu98XrepnwLfUj2RH vmiLbFcJz5s8Sfena8fEXvl4NljoCMJ/zpxoEzWKbAF/FSm77MOLrOv2RxLsrgw0pJ X-Received: by 2002:a05:7022:670f:b0:11b:88a7:e1b0 with SMTP id a92af1059eb24-12a96ed3ea0mr4115540c88.26.1774506038953; Wed, 25 Mar 2026 23:20:38 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:b7b4:352d:eb23:66e5]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12aa762430bsm3051833c88.10.2026.03.25.23.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 23:20:37 -0700 (PDT) Date: Wed, 25 Mar 2026 23:20:34 -0700 From: Dmitry Torokhov To: Dwaipayan Ray , Lukas Bulwahn , Joe Perches , Andy Whitcroft Cc: Jonathan Corbet , Shuah Khan , workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] checkpatch: allow correctly handle full files on stdin Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" checkpatch does not handle full files well when they are passed on stdin, because it does not know how to treat the text, and whether it is a C file, or a DTS file, or something else, and so it assumes that when it works with stdin it should be a unified diff. For full files it expects to have a file name as an argument and read the contents from disk. Unfortunately this does not well when trying to use checkpatch as an online linter and feed it contents of an editor buffer that have not made it to the disk yet. To solve the above introduce a new optional argument --stdin-filename=3DFILE that allows tell checkpatch the kind of file it is dealing with and apply appropriate set of checks and rules to it. Signed-off-by: Dmitry Torokhov --- Documentation/dev-tools/checkpatch.rst | 4 ++++ scripts/checkpatch.pl | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-too= ls/checkpatch.rst index dccede68698c..b521e3ca6ebf 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -68,6 +68,10 @@ Available options: =20 Show the diffed file position instead of the input file position. =20 + - --stdin-filename + + When using stdin, identify the file as FILE. + - -g, --git =20 Treat FILE as a single commit or a git revision range. diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e56374662ff7..e26951ceb36b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -57,6 +57,7 @@ my %ignore_type =3D (); my @ignore =3D (); my $help =3D 0; my $configuration_file =3D ".checkpatch.conf"; +my $stdin_filename; my $max_line_length =3D 100; my $ignore_perl_version =3D 0; my $minimum_perl_version =3D 5.10.0; @@ -94,6 +95,7 @@ Options: --emacs emacs compile window format --terse one line per report --showfile emit diffed file position, not input file pos= ition + --stdin-filename=3DFILE when using stdin, identify the file as FILE -g, --git treat FILE as a single commit or git revision= range single git commit with: @@ -323,6 +325,7 @@ GetOptions( 'showfile!' =3D> \$showfile, 'f|file!' =3D> \$file, 'g|git!' =3D> \$git, + 'stdin-filename=3Ds' =3D> \$stdin_filename, 'subjective!' =3D> \$check, 'strict!' =3D> \$check, 'ignore=3Ds' =3D> \@ignore, @@ -2652,6 +2655,10 @@ sub is_userspace { sub process { my $filename =3D shift; =20 + if ($filename eq '-' && defined($stdin_filename)) { + $filename =3D $stdin_filename; + } + my $linenr=3D0; my $prevline=3D""; my $prevrawline=3D""; @@ -2891,6 +2898,10 @@ sub process { $realfile =3D~ s@^([^/]*)/@@ if (!$file); $in_commit_log =3D 0; =20 + if ($realfile eq "-" && defined($stdin_filename)) { + $realfile =3D $stdin_filename; + } + $p1_prefix =3D $1; if (!$file && $tree && $p1_prefix ne '' && -e "$root/$p1_prefix") { --=20 2.53.0.1018.g2bb0e51243-goog --=20 Dmitry