All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts: A new script for checking duplicate struct declaration
@ 2021-04-01 11:09 Wan Jiabing
  2021-04-02  0:27 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Wan Jiabing @ 2021-04-01 11:09 UTC (permalink / raw)
  To: akpm, linux-kernel; +Cc: kael_w, Wan Jiabing

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.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 scripts/checkdeclares.pl | 53 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100755 scripts/checkdeclares.pl

diff --git a/scripts/checkdeclares.pl b/scripts/checkdeclares.pl
new file mode 100755
index 000000000000..d14a8cc39a4d
--- /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 \n";
+	print "We just warn 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";
+}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts: A new script for checking duplicate struct declaration
  2021-04-01 11:09 [PATCH] scripts: A new script for checking duplicate struct declaration Wan Jiabing
@ 2021-04-02  0:27 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2021-04-02  0:27 UTC (permalink / raw)
  To: Wan Jiabing; +Cc: linux-kernel, kael_w, Masahiro Yamada, Wan Jiabing

On Thu,  1 Apr 2021 19:09:43 +0800 Wan Jiabing <wanjiabing@vivo.com> wrote:

> 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.

include/linux/bpf-cgroup.h: struct bpf_prog is declared more than once.
include/linux/bpf.h: struct xdp_buff is declared more than once.
include/linux/bpf.h: struct sk_buff is declared more than once.
include/linux/bpf.h: struct btf_type is declared more than once.
include/linux/debug_locks.h: struct task_struct is declared more than once.
include/linux/fs.h: struct iov_iter is declared more than once.
include/linux/fs.h: struct files_struct is declared more than once.
include/linux/gpio.h: struct device is declared more than once.
include/linux/host1x.h: struct host1x is declared more than once.
include/linux/intel_rapl.h: struct rapl_package is declared more than once.
include/linux/libnvdimm.h: struct device is declared more than once.
include/linux/lightnvm.h: struct nvm_rq is declared more than once.
include/linux/memcontrol.h: struct mem_cgroup is declared more than once.
include/linux/mount.h: struct path is declared more than once.
include/linux/mutex.h: struct ww_acquire_ctx is declared more than once.
include/linux/netfilter.h: struct flowi is declared more than once.
include/linux/netfilter.h: struct nf_conntrack_tuple is declared more than once.
include/linux/netfilter.h: struct nlattr is declared more than once.
include/linux/netfilter.h: struct nf_conn is declared more than once.
include/linux/profile.h: struct pt_regs is declared more than once.
include/linux/trace_events.h: struct trace_array is declared more than once.

Sigh.  I keep telling them - "put the forward declaration at
top-of-file so it doesn't get duplicated later on".  Nobody listens to
Andrew.

> --- /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 \n";
> +	print "We just warn of struct declaration duplicates\n";

Not quite accurate.  I added this fixup:

--- a/scripts/checkdeclares.pl~scripts-a-new-script-for-checking-duplicate-struct-declaration-fix
+++ a/scripts/checkdeclares.pl
@@ -15,8 +15,8 @@
 use strict;
 
 sub usage {
-	print "Usage: checkdeclares.pl \n";
-	print "We just warn of struct declaration duplicates\n";
+	print "Usage: checkdeclares.pl file1.h ...\n";
+	print "Warns of struct declaration duplicates\n";
 	exit 1;
 }
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-02  0:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 11:09 [PATCH] scripts: A new script for checking duplicate struct declaration Wan Jiabing
2021-04-02  0:27 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.