From patchwork Wed Dec 20 23:46:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 122501 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp163976qgn; Wed, 20 Dec 2017 15:46:38 -0800 (PST) X-Google-Smtp-Source: ACJfBoumDKDFumXbNqcV2g3rZl3HayRaPCnIPbFWsdhnb8txYkh/B8YabNHg/rwtQeRy/Ks06iwO X-Received: by 10.159.231.24 with SMTP id w24mr8408209plq.434.1513813597947; Wed, 20 Dec 2017 15:46:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513813597; cv=none; d=google.com; s=arc-20160816; b=JVZboA0FRtWWB19ZnjAjB9umhV/atxNgZzcTvQNw7ijEXE7M89G60QT49AhjoTUoqh dTmxFc+oG28hWeCfA++ejmkULgxiCSw1IUd7PzDf2Dt9+O8wbHPddbpMBoNG6ttQzFNT gR3EhKbsRzcJObUQeTrzBwSWuIGeZqMM2gjO/+QgwuUtJGYyas2pj0qTEZRt5Pm8738Q uUvkYngxFmbmEAD1/84ldJRph8ewpPWZQ77lO2VpiNLZZYN1Zt/p/YrcYzbNmXBQqa4l TWIJLSMSr35vwKDYDEGLMaHsNoKtyu1toczrcRXty3uFg+G/VifG5T8XxGEbNjMe7ewg Q6Eg== 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=PZCARu32P9w7sKy3d3poPR1oQ2q1BQ2p2yh52ZqWmCI=; b=J6X/VSloYSbIkTjD7pNBgk3B2MelGW2f+FB0oDFhk9v+CCFwik10PQYDqvBKl8zGel QZGKndk+PZSlonlaELe5n0BzCuHFzATxgPMxYPt3poXgCIjRMaUxZDmVA7JgnRMzJuUz fgOgvXdlV2Vf1R9h4JO3Sw0NSezYi7mgNLhdXTzPAhmD5cC1ws6osyQzx4okTxc8MR/z nogOcYL1xawnn55mJFNA4VsdROxY/C1dZUULEYgP5TMLjSv6IdrhwBeWgZbR8WIIMB6X HV3B2OgOKNflJwwEiO5nz7YtsdIAO2tdglu2lY5WgJNbwzsaeHYedcihsyX7iCdHO+tB iZrw== 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 y14si12659055pgo.115.2017.12.20.15.46.37; Wed, 20 Dec 2017 15:46:37 -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 S1756582AbdLTXqd (ORCPT + 28 others); Wed, 20 Dec 2017 18:46:33 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:39089 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754303AbdLTXqa (ORCPT ); Wed, 20 Dec 2017 18:46:30 -0500 Received: by mail-pf0-f195.google.com with SMTP id l24so13220084pfj.6 for ; Wed, 20 Dec 2017 15:46:30 -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=PZCARu32P9w7sKy3d3poPR1oQ2q1BQ2p2yh52ZqWmCI=; b=o9tOFpCpV0b1jkDiPkdy/IC2Wj8TH6UBv2VCq2JVw16P0BHeWhFWMphJjncQTOoB75 APwEE/1RjuQVU0qp+fJGEJn3pvMSKFL4QicZ9yKAegKRdELaLkjrw59se8DwhmPepNXL HZf22bTVe3aoYwfBxwhvQF2mk4WSFLzxcDsq9PGNT8gaeKqJnQPAVkz6n4dm+FlfLxMP mrsnFQ9IBd+GVvO7MY3MrKVm8ROdBwpjHtvLn1KrJBqqOv5PkAWjb5VA2cJYmiQWOxAK i8+dSujUrufUS3APInJju8/MyvqTvQMbpqkQzfvXAD+Yq2vZuUwtNv5TVG/7UEGJW19r jiwQ== X-Gm-Message-State: AKGB3mIN3VMDJbvg4f601AiaLZdq8NcscMQL+GHEKfMD8OvL6T5o1FrD 68zCmxs/f5SeETgm4872MwBMU7MXAQ== X-Received: by 10.98.215.90 with SMTP id v26mr8545413pfl.174.1513813589675; Wed, 20 Dec 2017 15:46:29 -0800 (PST) Received: from xps15.usacommunications.tv (24-223-123-72.static.usa-companies.net. [24.223.123.72]) by smtp.googlemail.com with ESMTPSA id r1sm36855108pfe.99.2017.12.20.15.46.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2017 15:46:29 -0800 (PST) From: Rob Herring To: linux-kernel@vger.kernel.org, Thomas Gleixner , Joe Perches Cc: Andy Whitcroft , Greg Kroah-Hartman , Philippe Ombredanne Subject: [PATCH v4] checkpatch.pl: Add SPDX license tag check Date: Wed, 20 Dec 2017 17:46:25 -0600 Message-Id: <20171220234625.16521-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: Greg Kroah-Hartman Cc: Thomas Gleixner Cc: Philippe Ombredanne Signed-off-by: Rob Herring --- Thomas, if you are inclined and Joe is happy with this, can you add this on top of your series adding license-rules.rst. v4: - Reference license-rules.rst - Add comment style checks based on file types - Check .rst files 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. scripts/checkpatch.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) -- 2.14.1 Reviewed-by: Philippe Ombredanne diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 31031f10fe56..0324f845011d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2866,6 +2866,31 @@ sub process { } } +# check for using SPDX license tag at beginning of files + if ($rawline =~ /^\+/ && !($realline == 1 && $rawline =~ /^[\s\+]#!/)) { + my $ln = 1; + my $comment = ""; + + if ($realfile =~ /\.(h|s|S)$/) { + $comment = '/\*'; + } elsif ($realfile =~ /\.(c|dts|dtsi)$/) { + $comment = '//'; + } elsif ($realfile =~ /\.(sh|pl|py)$/) { + if ($prevrawline =~ /^[\s\+]#!/) { + $ln = 2; + } + $comment = '#'; + } elsif ($realfile =~ /\.rst$/) { + $comment = '..'; + } + + if ($comment !~ /^$/ && + ($realline == $ln xor $rawline =~ m@^\+$comment 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)$/);