From patchwork Fri Nov 10 20:19:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 118601 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp8365455qgn; Fri, 10 Nov 2017 12:19:15 -0800 (PST) X-Google-Smtp-Source: AGs4zMZBGbAG2Qx5Q4F6nFlWyMv/0qTDszCrViHUwvuXBL7xuFRpzY4UgAc5Zd95YUhm3LzP0qFt X-Received: by 10.101.78.5 with SMTP id r5mr1447158pgt.94.1510345155451; Fri, 10 Nov 2017 12:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510345155; cv=none; d=google.com; s=arc-20160816; b=kD/zUsp86BIIVso5yugDTJYDToUdz8DaOK9bUQj6XPgGiVCVJy7YC8EOiNp04GHuXO 9mTXHYJwg+1tJgyIoKyLNxazOYu6FCwn5Xttp99QHyYSuN2x6nawaoJpx/jA7yV/e/1l duRl+vBvxaKma0/wy0G/AjYiOGjJbP4FtqdHpLMY4xuYoLi8fvj0SF5eRAfpJZWYmcdn nzGnOHcm0vNmX7uyrt2CQxy/lEd/7FYrQjwIn2t6Ahsbu9XfreDpfPrIwf631q5iRrEr DP9H1pCgl6+iniyOcLzrFgeIORabpgp1qAuSnP6RmRI3TUWW3k+vUsZOupdNGyBSgVzW UGig== 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=qRTVsWK583AR4EVO2TZMp9nL+KPdi/9Mq4UN/pHa6Eg=; b=ZJIalcmXyxYnKbpVuRdUUp/8s9g5Y0kKZfI9+V6s99rctK8mB+tJfz0Q3PlAsFXaff 8m4Q+qfsiVmiz1qOnw5tNAn2bcgjjLJFyIRVf3Xx31UYpVLbha+mtjzskQnChkYz1TkB 6rXJlTgxImHEE3I79MuoIjopScNNDTF84KWkyxJZZFAHvoCFHTo70hCnX6XqntHU48Lm BZK8c9KfdzC9S6o/zHZH+iMHkR8YMlNnR8p+BeXn3UEjd6K+g6wVYCaCKsD30cH5WEpw VZOF7Uf9smk5CKNjuFGesBeTaG8vt6Uc2ezAmy5AcqQEvJEvaPJlGngNa3hWC4gv0Qp1 Rdxg== 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 t9si9808159pgf.185.2017.11.10.12.19.15; Fri, 10 Nov 2017 12:19:15 -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 S1753836AbdKJUTN (ORCPT + 25 others); Fri, 10 Nov 2017 15:19:13 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:53409 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750799AbdKJUTL (ORCPT ); Fri, 10 Nov 2017 15:19:11 -0500 Received: by mail-oi0-f65.google.com with SMTP id h6so7606775oia.10 for ; Fri, 10 Nov 2017 12:19:11 -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=qRTVsWK583AR4EVO2TZMp9nL+KPdi/9Mq4UN/pHa6Eg=; b=uIXxHPCKrtLye2+rvbr7p/HptKDZd+XWp5g4z2zcTDrcOsQv9KnLhiH3r29XaBwbnU d/rY5oH+s4ltLbRxnTLUAWcQpccND4WzcJwf5RqQSU6T2aWuRzr223ARGWNvsFM3Pp+p VJ2XZzw+6AWIHMwPkqtLThkIIU7Ytfcs926EWlIc+cmWreFyFySKNF3SWJnZvTULQHoi WttT3wXyQidR5PKoJULOt4pQQSiVL9f4wTQRT135m5LGEz9RBmKPykGVszk7iVm0eynW jlVOpg4T8AbT6feS4kyaeeRR0R3JxvMxH6P8MLTxXu8KZG2T1JURpN8IOHPOerEGCwpj fecA== X-Gm-Message-State: AJaThX7SsxUuizdjHPYGaCff+/r738BnPutgWBrrPOtXLGZCPNdsDlgt Lj6vL5qT3Yo7lvTD52ItmojWwPM= X-Received: by 10.202.8.149 with SMTP id 143mr931282oii.357.1510345151183; Fri, 10 Nov 2017 12:19:11 -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 s28sm4042701otc.36.2017.11.10.12.19.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 12:19:10 -0800 (PST) From: Rob Herring To: linux-kernel@vger.kernel.org Cc: Andy Whitcroft , Joe Perches , Greg Kroah-Hartman Subject: [PATCH v3] checkpatch.pl: Add SPDX license tag check Date: Fri, 10 Nov 2017 14:19:09 -0600 Message-Id: <20171110201909.6144-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 SPDX license tags are a thing now in the kernel[1]. It has also been decided to make them the first line in files. As Linus put it: "The real reason _I_ personally would like to see at least all the new SPDX lines to go at the very top of the file is that every time when we have some kind of ambiguity about placement, we end up with multiple cases, and then people don't notice when merging, and you end up having two - or you just end up having unnecessary merge conflicts because two different people picked two different choices)." Add a warning if SPDX-License-Identifier tag is not present in the first line (or 2nd for #! scripts) of files. [1] https://lwn.net/Articles/738235/ Cc: Andy Whitcroft Cc: Joe Perches Cc: Greg Kroah-Hartman Signed-off-by: Rob Herring --- v3: - Since we specify that the tag goes on the 1st or 2nd line, the logic can be greatly simplified compared to v2 because we can just use the line number. And now the check is improved too. I tested this on a variety of files and Greg's patches adding the tags. I did find one error in Greg's patches. The tags were placed on the 2nd line even for scripts without a "#!" line. Want to know which ones? Well, you'll have to run checkpatch. :) scripts/checkpatch.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.14.1 diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 8b80bac055e4..50633d44b49b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2865,6 +2865,20 @@ sub process { } } +# check for using SPDX license tag at beginning of files + if ($realfile !~ /Documentation/ && $rawline =~ /^\+/ && + !($realline == 1 && $rawline =~ /^[\s\+]#!/)) { + my $ln = 1; + + if ($realline == 2 && $prevrawline =~ /^[\s\+]#!/) { + $ln++; + } + if ($realline == $ln xor $rawline =~ m@^\+(#|//|/\*) SPDX-License-Identifier: @) { + WARN("SPDX_LICENSE_TAG", + "Missing or malformed SPDX-License-Identifier tag in 1st (or 2nd for scripts) line\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)$/);