Skip to content

Commit

Permalink
checkpatch: skip warnings for symbol links
Browse files Browse the repository at this point in the history
If there is a symbol link in the given patch, checkpatch.pl reports two
inaccurate warnings:

$ cat 0001-selftests-bpf-Add-mptcp-pm_nl_ctl-link.patch

 ... ...

 '''
 # diff --git a/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c \
 #            b/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c
 # new file mode 120000
 # index 000000000000..5a08c255b278
 # --- /dev/null
 # +++ b/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c
 # @@ -0,0 +1 @@
 # +../net/mptcp/pm_nl_ctl.c
 # \ No newline at end of file
 '''

$ ./scripts/checkpatch.pl 0001-selftests-bpf-Add-mptcp-pm_nl_ctl-link.patch

 '''
 WARNING: Missing or malformed SPDX-License-Identifier tag in line 1
 multipath-tcp#57: FILE: tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c:1:
 +../net/mptcp/pm_nl_ctl.c

 WARNING: adding a line without newline at end of file
 multipath-tcp#57: FILE: tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c:1:
 +../net/mptcp/pm_nl_ctl.c

 total: 0 errors, 2 warnings, 16 lines checked
 '''

This patch fixes this by adding a new variable $symbol_link in checkpatch
script, set it if the new file mode is 120000. Skip these two checks
"missing SPDX-License-Identifier" and "adding a line without newline at
end of file" if this variable is set.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
  • Loading branch information
Geliang Tang committed May 15, 2024
1 parent a357193 commit a7a39ff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,8 @@ sub process {

my $checklicenseline = 1;

my $symbol_link = 0;

sanitise_line_reset();
my $line;
foreach my $rawline (@rawlines) {
Expand Down Expand Up @@ -3564,6 +3566,11 @@ sub process {
# ignore non-hunk lines and lines being removed
next if (!$hunk_line || $line =~ /^-/);

# Check for symbol links
if ($line =~ /^new file mode 120000$/) {
$symbol_link = 1;
}

#trailing whitespace
if ($line =~ /^\+.*\015/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Expand Down Expand Up @@ -3756,7 +3763,8 @@ sub process {
}

if ($comment !~ /^$/ &&
$rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
$rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @ &&
$symbol_link =~ 1) {
WARN("SPDX_LICENSE_TAG",
"Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
Expand Down Expand Up @@ -3867,7 +3875,8 @@ sub process {
}

# check for adding lines without a newline.
if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/ &&
$symbol_link =~ 1) {
if (WARN("MISSING_EOF_NEWLINE",
"adding a line without newline at end of file\n" . $herecurr) &&
$fix) {
Expand Down

0 comments on commit a7a39ff

Please sign in to comment.