* [PATCH 0/2] checkpatch: Improve const struct tests
@ 2016-08-31 17:27 Joe Perches
2016-08-31 17:27 ` [PATCH 1/2] checkpatch: Externalize the structs that should be const Joe Perches
2016-08-31 17:27 ` [PATCH 2/2] const_structs.checkpatch: Add frequently used from Julia Lawall's list Joe Perches
0 siblings, 2 replies; 4+ messages in thread
From: Joe Perches @ 2016-08-31 17:27 UTC (permalink / raw)
To: Andrew Morton, linux-kernel; +Cc: Andy Whitcroft
Joe Perches (2):
checkpatch: Externalize the structs that should be const
const_structs.checkpatch: Add frequently defined from Julia Lawall's list
scripts/checkpatch.pl | 64 +++++++++++++++-------------------------
scripts/const_structs.checkpatch | 64 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 40 deletions(-)
create mode 100644 scripts/const_structs.checkpatch
--
2.10.0.rc2.1.gb2aa91d
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] checkpatch: Externalize the structs that should be const
2016-08-31 17:27 [PATCH 0/2] checkpatch: Improve const struct tests Joe Perches
@ 2016-08-31 17:27 ` Joe Perches
2016-08-31 17:27 ` [PATCH 2/2] const_structs.checkpatch: Add frequently used from Julia Lawall's list Joe Perches
1 sibling, 0 replies; 4+ messages in thread
From: Joe Perches @ 2016-08-31 17:27 UTC (permalink / raw)
To: Andrew Morton, Andy Whitcroft; +Cc: linux-kernel
Make it easier to add new structs that should be const.
Signed-off-by: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 64 +++++++++++++++-------------------------
scripts/const_structs.checkpatch | 39 ++++++++++++++++++++++++
2 files changed, 63 insertions(+), 40 deletions(-)
create mode 100644 scripts/const_structs.checkpatch
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8946904..bdc12d9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -54,6 +54,7 @@ my $min_conf_desc_length = 4;
my $spelling_file = "$D/spelling.txt";
my $codespell = 0;
my $codespellfile = "/usr/share/codespell/dictionary.txt";
+my $conststructsfile = "$D/const_structs.checkpatch";
my $color = 1;
my $allow_c99_comments = 1;
@@ -624,6 +625,29 @@ if ($codespell) {
$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
+my $const_structs = "";
+if (open(my $conststructs, '<', $conststructsfile)) {
+ while (<$conststructs>) {
+ my $line = $_;
+
+ $line =~ s/\s*\n?$//g;
+ $line =~ s/^\s*//g;
+
+ next if ($line =~ m/^\s*#/);
+ next if ($line =~ m/^\s*$/);
+ if ($line =~ /\s/) {
+ print("$conststructsfile: '$line' invalid - ignored\n");
+ next;
+ }
+
+ $const_structs .= '|' if ($const_structs ne "");
+ $const_structs .= $line;
+ }
+ close($conststructsfile);
+} else {
+ warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
+}
+
sub build_types {
my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
@@ -5902,46 +5926,6 @@ sub process {
}
# check for various structs that are normally const (ops, kgdb, device_tree)
- my $const_structs = qr{
- acpi_dock_ops|
- address_space_operations|
- backlight_ops|
- block_device_operations|
- dentry_operations|
- dev_pm_ops|
- dma_map_ops|
- extent_io_ops|
- file_lock_operations|
- file_operations|
- hv_ops|
- ide_dma_ops|
- intel_dvo_dev_ops|
- item_operations|
- iwl_ops|
- kgdb_arch|
- kgdb_io|
- kset_uevent_ops|
- lock_manager_operations|
- microcode_ops|
- mtrr_ops|
- neigh_ops|
- nlmsvc_binding|
- of_device_id|
- pci_raw_ops|
- pipe_buf_operations|
- platform_hibernation_ops|
- platform_suspend_ops|
- proto_ops|
- rpc_pipe_ops|
- seq_operations|
- snd_ac97_build_ops|
- soc_pcmcia_socket_ops|
- stacktrace_ops|
- sysfs_ops|
- tty_operations|
- uart_ops|
- usb_mon_operations|
- wd_ops}x;
if ($line !~ /\bconst\b/ &&
$line =~ /\bstruct\s+($const_structs)\b/) {
WARN("CONST_STRUCT",
diff --git a/scripts/const_structs.checkpatch b/scripts/const_structs.checkpatch
new file mode 100644
index 0000000..1b54425
--- /dev/null
+++ b/scripts/const_structs.checkpatch
@@ -0,0 +1,39 @@
+acpi_dock_ops
+address_space_operations
+backlight_ops
+block_device_operations
+dentry_operations
+dev_pm_ops
+dma_map_ops
+extent_io_ops
+file_lock_operations
+file_operations
+hv_ops
+ide_dma_ops
+intel_dvo_dev_ops
+item_operations
+iwl_ops
+kgdb_arch
+kgdb_io
+kset_uevent_ops
+lock_manager_operations
+microcode_ops
+mtrr_ops
+neigh_ops
+nlmsvc_binding
+of_device_id
+pci_raw_ops
+pipe_buf_operations
+platform_hibernation_ops
+platform_suspend_ops
+proto_ops
+rpc_pipe_ops
+seq_operations
+snd_ac97_build_ops
+soc_pcmcia_socket_ops
+stacktrace_ops
+sysfs_ops
+tty_operations
+uart_ops
+usb_mon_operations
+wd_ops
--
2.10.0.rc2.1.gb2aa91d
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] const_structs.checkpatch: Add frequently used from Julia Lawall's list
2016-08-31 17:27 [PATCH 0/2] checkpatch: Improve const struct tests Joe Perches
2016-08-31 17:27 ` [PATCH 1/2] checkpatch: Externalize the structs that should be const Joe Perches
@ 2016-08-31 17:27 ` Joe Perches
2016-08-31 22:39 ` Kees Cook
1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2016-08-31 17:27 UTC (permalink / raw)
To: Andrew Morton, linux-kernel; +Cc: Julia Lawall, Kees Cook
Using const is generally a good idea.
Julia Lawall has created a list of always const and almost always const
structs in the kernel sources.
Link: https://lkml.org/lkml/2016/8/28/95
Add the most frequently used (> 50 cases) that are almost always or
always const.
Signed-off-by: Joe Perches <joe@perches.com>
cc: Julia Lawall <julia.lawall@lip6.fr>
cc: Kees Cook <keescook@chromium.org>
---
scripts/const_structs.checkpatch | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/scripts/const_structs.checkpatch b/scripts/const_structs.checkpatch
index 1b54425..ac5f1267 100644
--- a/scripts/const_structs.checkpatch
+++ b/scripts/const_structs.checkpatch
@@ -2,38 +2,63 @@ acpi_dock_ops
address_space_operations
backlight_ops
block_device_operations
+clk_ops
+comedi_lrange
+component_ops
dentry_operations
dev_pm_ops
dma_map_ops
+driver_info
+drm_connector_funcs
+drm_encoder_funcs
+drm_encoder_helper_funcs
+ethtool_ops
extent_io_ops
file_lock_operations
file_operations
hv_ops
ide_dma_ops
+ide_port_ops
+inode_operations
intel_dvo_dev_ops
+irq_domain_ops
item_operations
+iwl_cfg
iwl_ops
kgdb_arch
kgdb_io
kset_uevent_ops
lock_manager_operations
+machine_desc
microcode_ops
+mlxsw_reg_info
mtrr_ops
neigh_ops
+net_device_ops
nlmsvc_binding
+nvkm_device_chip
of_device_id
pci_raw_ops
pipe_buf_operations
platform_hibernation_ops
platform_suspend_ops
proto_ops
+regmap_access_table
rpc_pipe_ops
+rtc_class_ops
+sd_desc
seq_operations
+sirfsoc_padmux
snd_ac97_build_ops
+snd_soc_component_driver
soc_pcmcia_socket_ops
stacktrace_ops
sysfs_ops
tty_operations
uart_ops
usb_mon_operations
+v4l2_ctrl_ops
+v4l2_ioctl_ops
+vm_operations_struct
+wacom_features
wd_ops
--
2.10.0.rc2.1.gb2aa91d
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] const_structs.checkpatch: Add frequently used from Julia Lawall's list
2016-08-31 17:27 ` [PATCH 2/2] const_structs.checkpatch: Add frequently used from Julia Lawall's list Joe Perches
@ 2016-08-31 22:39 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2016-08-31 22:39 UTC (permalink / raw)
To: Joe Perches; +Cc: Andrew Morton, LKML, Julia Lawall
On Wed, Aug 31, 2016 at 1:27 PM, Joe Perches <joe@perches.com> wrote:
> Using const is generally a good idea.
>
> Julia Lawall has created a list of always const and almost always const
> structs in the kernel sources.
>
> Link: https://lkml.org/lkml/2016/8/28/95
>
> Add the most frequently used (> 50 cases) that are almost always or
> always const.
>
> Signed-off-by: Joe Perches <joe@perches.com>
> cc: Julia Lawall <julia.lawall@lip6.fr>
> cc: Kees Cook <keescook@chromium.org>
Acked-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
Nexus Security
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-08-31 22:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-31 17:27 [PATCH 0/2] checkpatch: Improve const struct tests Joe Perches
2016-08-31 17:27 ` [PATCH 1/2] checkpatch: Externalize the structs that should be const Joe Perches
2016-08-31 17:27 ` [PATCH 2/2] const_structs.checkpatch: Add frequently used from Julia Lawall's list Joe Perches
2016-08-31 22:39 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox