diff options
author | Wan Jiabing <wanjiabing@vivo.com> | 2021-04-29 22:53:56 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2021-04-30 11:20:35 -0700 |
commit | 21917bded72cf33bdf02a153f7b477ab186a52ee (patch) | |
tree | 5331d5e9a3f28d9d8ee776ce16511b147775fe7a /scripts | |
parent | 439baedad52d3242ec1d2ed728bc195fd5577c05 (diff) |
scripts: a new script for checking duplicate struct declaration
checkdeclares: find struct declared more than once. Inspired by
checkincludes.pl.
This script checks for duplicate struct declares. Note that this will not
take into consideration macros, so you should run this only if you know
you do have real dups and do not have them under #ifdef's. You could also
just review the results.
[akpm@linux-foundation.org: fix usage message, grammar]
Link: https://lkml.kernel.org/r/20210401110943.1010796-1-wanjiabing@vivo.com
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/checkdeclares.pl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/checkdeclares.pl b/scripts/checkdeclares.pl new file mode 100644 index 000000000000..f6d551c84fc6 --- /dev/null +++ b/scripts/checkdeclares.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 +# +# checkdeclares: find struct declared more than once +# +# Copyright 2021 Wan Jiabing<wanjiabing@vivo.com> +# Inspired by checkincludes.pl +# +# This script checks for duplicate struct declares. +# Note that this will not take into consideration macros so +# you should run this only if you know you do have real dups +# and do not have them under #ifdef's. +# You could also just review the results. + +use strict; + +sub usage { + print "Usage: checkdeclares.pl file1.h ...\n"; + print "Warns of struct declaration duplicates\n"; + exit 1; +} + +if ($#ARGV < 0) { + usage(); +} + +my $dup_counter = 0; + +foreach my $file (@ARGV) { + open(my $f, '<', $file) + or die "Cannot open $file: $!.\n"; + + my %declaredstructs = (); + + while (<$f>) { + if (m/^\s*struct\s*(\w*);$/o) { + ++$declaredstructs{$1}; + } + } + + close($f); + + foreach my $structname (keys %declaredstructs) { + if ($declaredstructs{$structname} > 1) { + print "$file: struct $structname is declared more than once.\n"; + ++$dup_counter; + } + } +} + +if ($dup_counter == 0) { + print "No duplicate struct declares found.\n"; +} |