diff options
author | Joe Perches <joe@perches.com> | 2016-10-11 16:51:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-11 18:06:30 -0400 |
commit | bf1fa1dae68e1b58b7b7fd61bde654d37da1de57 (patch) | |
tree | a49132ae5825b5876b19a79f847d84caa8f80bc0 /scripts | |
parent | f333195d41e15e7b105ca270c7662204a1a9d0f5 (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-x | scripts/checkpatch.pl | 64 | ||||
-rw-r--r-- | scripts/const_structs.checkpatch | 39 |
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; | |||
54 | my $spelling_file = "$D/spelling.txt"; | 54 | my $spelling_file = "$D/spelling.txt"; |
55 | my $codespell = 0; | 55 | my $codespell = 0; |
56 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; | 56 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; |
57 | my $conststructsfile = "$D/const_structs.checkpatch"; | ||
57 | my $color = 1; | 58 | my $color = 1; |
58 | my $allow_c99_comments = 1; | 59 | my $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 | ||
628 | my $const_structs = ""; | ||
629 | if (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 | |||
627 | sub build_types { | 651 | sub 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 @@ | |||
1 | acpi_dock_ops | ||
2 | address_space_operations | ||
3 | backlight_ops | ||
4 | block_device_operations | ||
5 | dentry_operations | ||
6 | dev_pm_ops | ||
7 | dma_map_ops | ||
8 | extent_io_ops | ||
9 | file_lock_operations | ||
10 | file_operations | ||
11 | hv_ops | ||
12 | ide_dma_ops | ||
13 | intel_dvo_dev_ops | ||
14 | item_operations | ||
15 | iwl_ops | ||
16 | kgdb_arch | ||
17 | kgdb_io | ||
18 | kset_uevent_ops | ||
19 | lock_manager_operations | ||
20 | microcode_ops | ||
21 | mtrr_ops | ||
22 | neigh_ops | ||
23 | nlmsvc_binding | ||
24 | of_device_id | ||
25 | pci_raw_ops | ||
26 | pipe_buf_operations | ||
27 | platform_hibernation_ops | ||
28 | platform_suspend_ops | ||
29 | proto_ops | ||
30 | rpc_pipe_ops | ||
31 | seq_operations | ||
32 | snd_ac97_build_ops | ||
33 | soc_pcmcia_socket_ops | ||
34 | stacktrace_ops | ||
35 | sysfs_ops | ||
36 | tty_operations | ||
37 | uart_ops | ||
38 | usb_mon_operations | ||
39 | wd_ops | ||