From patchwork Fri Feb 2 15:40:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 126734 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp752921ljc; Fri, 2 Feb 2018 07:40:34 -0800 (PST) X-Google-Smtp-Source: AH8x227XTGStONgySue0UdGR3IcvZDugpAFYquSyyuczM/eHIoZow8safon5ORxEHGQhG/KRYXK7 X-Received: by 10.98.74.154 with SMTP id c26mr6056174pfj.188.1517586034488; Fri, 02 Feb 2018 07:40:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517586034; cv=none; d=google.com; s=arc-20160816; b=oOLWdv3Kf6LBM3OCAybxr7l4mx2UCe5x9v3nOUmPpIjKg7/QPF5Oz6bfOWi0HQPEyO WIoFQBKaOUMSSr6abezRo8iWPB6udfv4ucnjIuVlNNzjl9SenWJDcs9p2RsFEx8UQrL8 4Ft2/nyyOcqkw4hRlvgTheyI9crWFxhxthAA5EWXOWbM4wkuzzDfxkl+U9IckwpUmgJq GtiUitmHlwn3pxTEZ0tIVYfaYv6gpZlPX1EnVKtuEnwF+qRNWfgmKzU1kUE+PRUXSk7G 5aGBy3fd6OayYWf+cz5RffqaOzs+CKgnYajxR2y121BW3zcsoucLOdYfs5Q41fLKVKM4 pymA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Dyc2s/0LAJmLfq8VwbhZI2gdgoIwzQlkb/vA3weIKgc=; b=JVr5/zjvzkUChYT7WlkVpwQ524763FHmQRlLkvBtImPASzz8NMr4cXvjH1B6+YHR00 xjZqk8fXpf04JHK1zkJKMKzixU0Nbon0HuKcQj0L21N7D+88kn9iWMNcDu9Thd6BWHrT 93QWx4CEuU9sAHsj+o6Usg4glgqrj2mF/YuQacxDdNytNzEvl5BCL+0CXjniVEjYpqw/ gu8/PfJMBNS5M8aCP+Ui3WT8XLsg/UsklxPUIZMJJBc5mzaxI7Xt0PKZxKfGxOf10GZ7 AF9ggoOsROJ/6CuRp7hniTw7jMFfC7dKd/yNVnI1I+ixw+dWDAxa5/toQ4cyhwklQta3 1lZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2si1616379pgs.580.2018.02.02.07.40.34; Fri, 02 Feb 2018 07:40:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752175AbeBBPkd (ORCPT + 28 others); Fri, 2 Feb 2018 10:40:33 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:45012 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751569AbeBBPk2 (ORCPT ); Fri, 2 Feb 2018 10:40:28 -0500 Received: by mail-ot0-f194.google.com with SMTP id l5so14538260otj.11 for ; Fri, 02 Feb 2018 07:40:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Dyc2s/0LAJmLfq8VwbhZI2gdgoIwzQlkb/vA3weIKgc=; b=Eyun2UV5SwVk3vAb0e0IvmigHeSfjwbibGv4k0JOxB3jzqx0G54hyISnWMIa4CrS8R OMoQiFc2VCKVMCh5rQKrI/R/QUZnMqFeQ4mfLbe4kwvNZzikpB11w/H4c4xBkmTVTdMj KeGfHcTAB7xd8VXkNrG5SVI6S/+PCpkiP75iElP1dgL4KLbL1pB+0Hn8+nAM/UU7odYL 95GURa60UVnhBloRnIQVVmem48Q60E8UP/KMyPmcOfML3dZ4WVJnrH6osK1+zMXOvOwl 7ZmcGOwhDWLYlns+sQJYIA7z+OxW8U8ntc1NN1yRLXb1TcRxTgctMSVWK20mW95GiPej VdOg== X-Gm-Message-State: AKwxytdawwfv3dV0zyoMGiEgX70rZOimX+TDOLgI1SEhWRnXzvoP2zWY q7OtW6Rfocm9VWinCh/0BQ== X-Received: by 10.157.26.74 with SMTP id u10mr6015354otu.22.1517586028186; Fri, 02 Feb 2018 07:40:28 -0800 (PST) Received: from xps15.herring.priv (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id s30sm1145186otd.53.2018.02.02.07.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 07:40:27 -0800 (PST) From: Rob Herring To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Joe Perches , Andy Whitcroft , Greg Kroah-Hartman , Thomas Gleixner , Philippe Ombredanne Subject: [PATCH v6] checkpatch.pl: Add SPDX license tag check Date: Fri, 2 Feb 2018 09:40:26 -0600 Message-Id: <20180202154026.15298-1-robh@kernel.org> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add SPDX license tag check based on the rules defined in Documentation/process/license-rules.rst. To summarize, SPDX license tags should be on the 1st line (or 2nd line in scripts) using the appropriate comment style for the file type. Cc: Andy Whitcroft Cc: Joe Perches Cc: Thomas Gleixner Cc: Philippe Ombredanne Acked-by: Greg Kroah-Hartman Signed-off-by: Rob Herring --- v6: - Dropped script extension check and only look for #!/... on 1st line. A text executable file was not reliable either. - Support .awk and .tc which may or may not have a #!/. - Fixed a typo in script "#!" regex and also match on first /. - Add Greg's ack. scripts/checkpatch.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.14.1 Signed-off-by: Joe Perches Acked-by: Philippe Ombredanne diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ba03f17ff662..6db245e5f93b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2225,6 +2225,8 @@ sub process { my $camelcase_file_seeded = 0; + my $checklicenseline = 1; + sanitise_line_reset(); my $line; foreach my $rawline (@rawlines) { @@ -2416,6 +2418,7 @@ sub process { } else { $check = $check_orig; } + $checklicenseline = 1; next; } @@ -2866,6 +2869,30 @@ sub process { } } +# check for using SPDX license tag at beginning of files + if ($realline == $checklicenseline) { + if ($rawline =~ /^[ \+]\s*\#\!\s*\//) { + $checklicenseline = 2; + } elsif ($rawline =~ /^\+/) { + my $comment = ""; + if ($realfile =~ /\.(h|s|S)$/) { + $comment = '/*'; + } elsif ($realfile =~ /\.(c|dts|dtsi)$/) { + $comment = '//'; + } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) { + $comment = '#'; + } elsif ($realfile =~ /\.rst$/) { + $comment = '..'; + } + + if ($comment !~ /^$/ && + $rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) { + WARN("SPDX_LICENSE_TAG", + "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr); + } + } + } + # check we are in a valid source file if not then ignore this hunk next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);