aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2016-10-11 16:51:56 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-11 18:06:30 -0400
commitbf1fa1dae68e1b58b7b7fd61bde654d37da1de57 (patch)
treea49132ae5825b5876b19a79f847d84caa8f80bc0 /scripts
parentf333195d41e15e7b105ca270c7662204a1a9d0f5 (diff)
checkpatch: externalize the structs that should be const
Make it easier to add new structs that should be const. Link: http://lkml.kernel.org/r/e5a8da43e7c11525bafbda1ca69a8323614dd942.1472664220.git.joe@perches.com Signed-off-by: Joe Perches <joe@perches.com> Cc: Julia Lawall <julia.lawall@lip6.fr> Cc: Kees Cook <keescook@chromium.org> Cc: Andy Whitcroft <apw@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl64
-rw-r--r--scripts/const_structs.checkpatch39
2 files changed, 63 insertions, 40 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 37d8b91ac198..4ecb66c595f4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -54,6 +54,7 @@ my $min_conf_desc_length = 4;
54my $spelling_file = "$D/spelling.txt"; 54my $spelling_file = "$D/spelling.txt";
55my $codespell = 0; 55my $codespell = 0;
56my $codespellfile = "/usr/share/codespell/dictionary.txt"; 56my $codespellfile = "/usr/share/codespell/dictionary.txt";
57my $conststructsfile = "$D/const_structs.checkpatch";
57my $color = 1; 58my $color = 1;
58my $allow_c99_comments = 1; 59my $allow_c99_comments = 1;
59 60
@@ -624,6 +625,29 @@ if ($codespell) {
624 625
625$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; 626$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
626 627
628my $const_structs = "";
629if (open(my $conststructs, '<', $conststructsfile)) {
630 while (<$conststructs>) {
631 my $line = $_;
632
633 $line =~ s/\s*\n?$//g;
634 $line =~ s/^\s*//g;
635
636 next if ($line =~ m/^\s*#/);
637 next if ($line =~ m/^\s*$/);
638 if ($line =~ /\s/) {
639 print("$conststructsfile: '$line' invalid - ignored\n");
640 next;
641 }
642
643 $const_structs .= '|' if ($const_structs ne "");
644 $const_structs .= $line;
645 }
646 close($conststructsfile);
647} else {
648 warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
649}
650
627sub build_types { 651sub build_types {
628 my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; 652 my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
629 my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)"; 653 my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
@@ -5912,46 +5936,6 @@ sub process {
5912 } 5936 }
5913 5937
5914# check for various structs that are normally const (ops, kgdb, device_tree) 5938# check for various structs that are normally const (ops, kgdb, device_tree)
5915 my $const_structs = qr{
5916 acpi_dock_ops|
5917 address_space_operations|
5918 backlight_ops|
5919 block_device_operations|
5920 dentry_operations|
5921 dev_pm_ops|
5922 dma_map_ops|
5923 extent_io_ops|
5924 file_lock_operations|
5925 file_operations|
5926 hv_ops|
5927 ide_dma_ops|
5928 intel_dvo_dev_ops|
5929 item_operations|
5930 iwl_ops|
5931 kgdb_arch|
5932 kgdb_io|
5933 kset_uevent_ops|
5934 lock_manager_operations|
5935 microcode_ops|
5936 mtrr_ops|
5937 neigh_ops|
5938 nlmsvc_binding|
5939 of_device_id|
5940 pci_raw_ops|
5941 pipe_buf_operations|
5942 platform_hibernation_ops|
5943 platform_suspend_ops|
5944 proto_ops|
5945 rpc_pipe_ops|
5946 seq_operations|
5947 snd_ac97_build_ops|
5948 soc_pcmcia_socket_ops|
5949 stacktrace_ops|
5950 sysfs_ops|
5951 tty_operations|
5952 uart_ops|
5953 usb_mon_operations|
5954 wd_ops}x;
5955 if ($line !~ /\bconst\b/ && 5939 if ($line !~ /\bconst\b/ &&
5956 $line =~ /\bstruct\s+($const_structs)\b/) { 5940 $line =~ /\bstruct\s+($const_structs)\b/) {
5957 WARN("CONST_STRUCT", 5941 WARN("CONST_STRUCT",
diff --git a/scripts/const_structs.checkpatch b/scripts/const_structs.checkpatch
new file mode 100644
index 000000000000..1b54425f6c89
--- /dev/null
+++ b/scripts/const_structs.checkpatch
@@ -0,0 +1,39 @@
1acpi_dock_ops
2address_space_operations
3backlight_ops
4block_device_operations
5dentry_operations
6dev_pm_ops
7dma_map_ops
8extent_io_ops
9file_lock_operations
10file_operations
11hv_ops
12ide_dma_ops
13intel_dvo_dev_ops
14item_operations
15iwl_ops
16kgdb_arch
17kgdb_io
18kset_uevent_ops
19lock_manager_operations
20microcode_ops
21mtrr_ops
22neigh_ops
23nlmsvc_binding
24of_device_id
25pci_raw_ops
26pipe_buf_operations
27platform_hibernation_ops
28platform_suspend_ops
29proto_ops
30rpc_pipe_ops
31seq_operations
32snd_ac97_build_ops
33soc_pcmcia_socket_ops
34stacktrace_ops
35sysfs_ops
36tty_operations
37uart_ops
38usb_mon_operations
39wd_ops