Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Joe Perches and committed by
Linus Torvalds
bf1fa1da f333195d

+63 -40
+24 -40
scripts/checkpatch.pl
··· 54 54 my $spelling_file = "$D/spelling.txt"; 55 55 my $codespell = 0; 56 56 my $codespellfile = "/usr/share/codespell/dictionary.txt"; 57 + my $conststructsfile = "$D/const_structs.checkpatch"; 57 58 my $color = 1; 58 59 my $allow_c99_comments = 1; 59 60 ··· 624 623 } 625 624 626 625 $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; 626 + 627 + my $const_structs = ""; 628 + if (open(my $conststructs, '<', $conststructsfile)) { 629 + while (<$conststructs>) { 630 + my $line = $_; 631 + 632 + $line =~ s/\s*\n?$//g; 633 + $line =~ s/^\s*//g; 634 + 635 + next if ($line =~ m/^\s*#/); 636 + next if ($line =~ m/^\s*$/); 637 + if ($line =~ /\s/) { 638 + print("$conststructsfile: '$line' invalid - ignored\n"); 639 + next; 640 + } 641 + 642 + $const_structs .= '|' if ($const_structs ne ""); 643 + $const_structs .= $line; 644 + } 645 + close($conststructsfile); 646 + } else { 647 + warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; 648 + } 627 649 628 650 sub build_types { 629 651 my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; ··· 5936 5912 } 5937 5913 5938 5914 # check for various structs that are normally const (ops, kgdb, device_tree) 5939 - my $const_structs = qr{ 5940 - acpi_dock_ops| 5941 - address_space_operations| 5942 - backlight_ops| 5943 - block_device_operations| 5944 - dentry_operations| 5945 - dev_pm_ops| 5946 - dma_map_ops| 5947 - extent_io_ops| 5948 - file_lock_operations| 5949 - file_operations| 5950 - hv_ops| 5951 - ide_dma_ops| 5952 - intel_dvo_dev_ops| 5953 - item_operations| 5954 - iwl_ops| 5955 - kgdb_arch| 5956 - kgdb_io| 5957 - kset_uevent_ops| 5958 - lock_manager_operations| 5959 - microcode_ops| 5960 - mtrr_ops| 5961 - neigh_ops| 5962 - nlmsvc_binding| 5963 - of_device_id| 5964 - pci_raw_ops| 5965 - pipe_buf_operations| 5966 - platform_hibernation_ops| 5967 - platform_suspend_ops| 5968 - proto_ops| 5969 - rpc_pipe_ops| 5970 - seq_operations| 5971 - snd_ac97_build_ops| 5972 - soc_pcmcia_socket_ops| 5973 - stacktrace_ops| 5974 - sysfs_ops| 5975 - tty_operations| 5976 - uart_ops| 5977 - usb_mon_operations| 5978 - wd_ops}x; 5979 5915 if ($line !~ /\bconst\b/ && 5980 5916 $line =~ /\bstruct\s+($const_structs)\b/) { 5981 5917 WARN("CONST_STRUCT",
+39
scripts/const_structs.checkpatch
··· 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