lkml.org 
[lkml]   [2015]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] Add coccinelle script that makes sure that tables are NULL terminated
Date
Signed-off-by: Daniel Granat <d.granat@samsung.com>
---
scripts/coccinelle/misc/device_id_tables.cocci | 95 ++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
create mode 100644 scripts/coccinelle/misc/device_id_tables.cocci

diff --git a/scripts/coccinelle/misc/device_id_tables.cocci b/scripts/coccinelle/misc/device_id_tables.cocci
new file mode 100644
index 0000000..5968984
--- /dev/null
+++ b/scripts/coccinelle/misc/device_id_tables.cocci
@@ -0,0 +1,95 @@
+/// Make sure '*_device_id$' tables are NULL terminated
+//
+// Keywords: device_id
+// Confidence: Medium
+// Options: --include-headers
+
+virtual org
+virtual report
+virtual patch
+
+@initialize:python@
+@@
+import re
+
+postfix = '_device_id$'
+prefix_list = ['platform', 'of', 'i2c']
+
+@r1 depends on patch || org || report@
+position p1;
+identifier var, arr;
+identifier struct_name;
+expression E;
+@@
+
+(
+struct struct_name arr[] = {
+ ...,
+ {
+ .var = E,
+ }
+ @p1
+};
+|
+struct struct_name arr[] = {
+ ...,
+ { ..., var, ... },
+ @p1
+};
+)
+
+@script:python depends on report@
+struct_name << r1.struct_name;
+p1 << r1.p1;
+arr << r1.arr;
+pattern;
+@@
+
+for i in prefix_list:
+ pattern = str(i)+postfix
+ if re.match(pattern, struct_name) != None:
+ print "\nCOCCI: \"%s\" matchs required pattern \"%s\"" % (struct_name, pattern)
+ msg = "\"%s\" is not NULL terminated at line %s" % (arr, p1[0].line)
+ coccilib.report.print_report(p1[0],msg)
+ break
+
+@script:python match depends on patch@
+struct_name << r1.struct_name;
+matched_name;
+pattern;
+@@
+
+coccinelle.matched_name = ''
+
+for i in prefix_list:
+ pattern = str(i)+postfix
+ if re.match(pattern, struct_name) != None:
+ coccinelle.matched_name = struct_name
+ break
+
+@r2 depends on patch@
+position r1.p1;
+identifier var, arr;
+identifier match.matched_name;
+expression E;
+@@
+
+(
+struct matched_name arr[] = {
+ ...,
+ {
+ .var = E,
+- }
+ @p1
++ },
++ {},
+};
+|
+struct matched_name arr[] = {
+ ...,
+ { ..., var, ... },
+ @p1
++ {},
+};
+)
+
--
1.9.1


\
 
 \ /
  Last update: 2015-02-27 14:41    [W:0.148 / U:0.424 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site