Skip to contentSkip to conversation

checkpatch: Add of_device_id to structs that should be const

PATCH In review Joe Perches 2 participants 2 messages Feb 9, 2015 – Feb 10, 2015 Checkpatch

lore
Share & tools
lore

Joe Perches

author maintainer
#0 lore raw

PATCH 1/1 checkpatch: Add of_device_id to structs that should be const

Uses of struct of_device_id are most commonly const.

Suggest using it as such.

---
 scripts/checkpatch.pl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +5 -3
index 3642b0d..368db0d 100755
@@ -5216,8 +5216,9 @@ sub process {
 			     "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
 		}
 
-# check for various ops structs, ensure they are const.
-		my $struct_ops = qr{acpi_dock_ops|
+# 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|
@@ -5240,6 +5241,7 @@ sub process {
 				mtrr_ops|
 				neigh_ops|
 				nlmsvc_binding|
+				of_device_id|
 				pci_raw_ops|
 				pipe_buf_operations|
 				platform_hibernation_ops|
@@ -5255,7 +5257,7 @@ sub process {
 				usb_mon_operations|
 				wd_ops}x;
 		if ($line !~ /\bconst\b/ &&
-		    $line =~ /\bstruct\s+($struct_ops)\b/) {
+		    $line =~ /\bstruct\s+($const_structs)\b/) {
 			WARN("CONST_STRUCT",
 			     "struct $1 should normally be const\n" .
 				$herecurr);
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Joe Perches

Uses of struct of_device_id are most commonly const.

Suggest using it as such.

Quoted 39 lines
---
 scripts/checkpatch.pl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +5 -3
index 3642b0d..368db0d 100755
@@ -5216,8 +5216,9 @@ sub process {
                             "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
                }
 
-# check for various ops structs, ensure they are const.
-               my $struct_ops = qr{acpi_dock_ops|
+# 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|
@@ -5240,6 +5241,7 @@ sub process {
                                mtrr_ops|
                                neigh_ops|
                                nlmsvc_binding|
+                               of_device_id|
                                pci_raw_ops|
                                pipe_buf_operations|
                                platform_hibernation_ops|
@@ -5255,7 +5257,7 @@ sub process {
                                usb_mon_operations|
                                wd_ops}x;
                if ($line !~ /\bconst\b/ &&
-                   $line =~ /\bstruct\s+($struct_ops)\b/) {
+                   $line =~ /\bstruct\s+($const_structs)\b/) {
                        WARN("CONST_STRUCT",
                             "struct $1 should normally be const\n" .
                                $herecurr);