Skip to content

Commit bf1fa1d

Browse files
JoePerchestorvalds
authored andcommitted
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>
1 parent f333195 commit bf1fa1d

2 files changed

Lines changed: 63 additions & 40 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
my $spelling_file = "$D/spelling.txt";
5555
my $codespell = 0;
5656
my $codespellfile = "/usr/share/codespell/dictionary.txt";
57+
my $conststructsfile = "$D/const_structs.checkpatch";
5758
my $color = 1;
5859
my $allow_c99_comments = 1;
5960

@@ -624,6 +625,29 @@ sub hash_show_words {
624625

625626
$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
626627

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+
627651
sub build_types {
628652
my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
629653
my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
@@ -5912,46 +5936,6 @@ sub process {
59125936
}
59135937

59145938
# 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;
59555939
if ($line !~ /\bconst\b/ &&
59565940
$line =~ /\bstruct\s+($const_structs)\b/) {
59575941
WARN("CONST_STRUCT",

‎scripts/const_structs.checkpatch‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)